Shop OBEX P1 Docs P2 Docs Learn Events
MCP23017 Help — Parallax Forums

MCP23017 Help

Alan BradfordAlan Bradford Posts: 172
edited 2011-05-06 11:39 in BASIC Stamp
I have a problem.
I am using a BS2p24 with MCP23017 I/O Expaners (5)
I breadboarded the circuit and tested the SW with MCP23016 chips.
When I spun the boards I used the MCP23017 data sheet. Big Duh there!
Now I am having problems initialising the 17.
All I need to do set the first 2 as all inputs and the last 3 as outputs.
I know my sample code is all wrong.
I have the data sheet, and cannot make heads or tails about the registers.
Thanks in advance if anyone can help.

Alan Bradford
Plasma Technologies

' {$STAMP BS2p}
' {$PBASIC 2.5}
'
' =========================================================================



' I/O

SDA PIN 0 ' I2C data pin
SCL PIN SDA + 1 ' I2C clock pin



DevType CON %0100 << 4 ' Device type
DevAddr CON %000 << 1 ' address = %000 -> %111
Wr23017 CON DevType | DevAddr | 0 ' write to MCP23017
Rd23017 CON DevType | DevAddr | 1 ' read from MCP23017
IODIRA CON 0
IODIRB CON 16
OLATA CON 10
OLATB CON 26
GPIOA CON $12
GPIOB CON $13
PAUSE 2000

I2COUT SDA, Wr23017, IODIRA, [%00000000] ' GP0 pins are outputs
I2COUT SDA, Wr23017, IODIRB, [%00000000]
I2COUT SDA, Wr23017, OLATA, [%11111111]
I2COUT SDA, Wr23017, OLATB, [%11111111]


addr VAR Word ' ee address for strings
column VAR Byte
idx VAR Nib

btns VAR Nib
ab VAR Byte

Main:
ab=$ff
I2COUT SDA, Wr23017,gpioa, [%11111111] ' update port 1 bits
I2COUT SDA, Wr23017,gpiob, [%11111111] ' update port 1 bits
' I2COUT SDA, Wr23017, OLATA, [%11111111]
'I2COUT SDA, Wr23017, OLATB, [%11111111]
DEBUG " 1"
PAUSE 1000
ab=$00
I2COUT SDA, Wr23017,gpioa, [%00000000] ' update port 1 bits
I2COUT SDA, Wr23017,gpiob, [%00000000] ' update port 1 bits
' I2COUT SDA, Wr23017, OLATA, [%11111111]
'I2COUT SDA, Wr23017, OLATB, [%11111111]
DEBUG " 0"
PAUSE 2000
GOTO main



END
Sign In or Register to comment.