I got some Microchip MCP23017 I/O Expander chips, which interface via i2c. I’ve been trying to get an Atom PRO to communicate with this chip, but have not had any success so far. From what I have read of the MCP23017’s datasheet, it looks like I am doing things properly.
However, it seems like the Atom PRO is just locking up when it executes the i2cout command. Nothing happens after it gets to that i2cout command, and I have a serout and turn on an LED right after that. Neither of those things happen.
Is there something I am missing about the i2cout command? Is there some other setup I need to do for serial communications to work, including i2c? I didn’t see any mention of extra setup in the Atom PRO manual.
Here is the code:
[code]’
’ I2C Test Program for Microchip MCP23017 I/O Expander
’
’
greenLED con p8
yellowLED con p7
redLED con p6
’ I2C Configuration
SCL con p12
SDA con p13
’ Microchip MCP27013 I/O Expander Configuration
ctrlwr con %01000000 ’ Control Byte (Write)
ctrlrd con %01000001 ’ Control Byte (Read)
iocona con 0x05 ’ Port A I/O Configuration Address
ioconseta con %11100011 ’ Port A ICON register setting
iodira con 0x00 ’ Port A Direction Bit Control Address
iobitsa con %00000000 ’ Port A Direction Bit Settings (0 = output, 1 = input)
ioconb con 0x15 ’ Port B
ioconsetb con %11100011 ’ Port B
iodirb con 0x10 ’ Port B Direction Bit Control Address
iobitsb con %00000000 ’ Port B Direction Bit Settings (0 = output, 1 = input)
high redLED
high yellowLED
high greenLED
pause 1000
low redLED
low yellowLED
low greenLED
Main:
gosub WriteI2C [iocona, ioconseta]
gosub WriteI2C [ioconb, ioconsetb]
gosub WriteI2c [iodira, iobitsa]
gosub WriteI2c [iodirb, iobitsb]
goto Main
address var byte
outdat var byte
WriteI2C [address, outdat]
high yellowLED
pause 1000
low yellowLED
i2cout SDA,SCL, Failed, ctrlwr, address, [outdat]
serout S_OUT, NE2400, "Wrote byte ", BIN outdat, ", at address ", BIN address, 13]
high greenLED
pause 1000
low greenLED
goto WriteDone
Failed:
serout S_OUT, NE2400, “Output to I/O Expander failed!”, 13]
high redLED
pause 1000
low redLED
goto Main
WriteDone:
return
end[/code]
I know the WriteI2C subroutine is getting executed because the yellow LED comes on and goes off. I never see the green LED blink or the serout command execute. I also don’t see any branch to the Failed section of code.
8-Dale