Hi!
Searched around the forum but did not found a solution to my problem.
This is what I have:
One MCP23016 connected to PIC18F4550 via I2C.
Pins A0,A1,A2,Vss1,Vss2 and Vss3 grounded, TP flouting...
CLK connected to +5V with 3k9 resistor and 33pF to gnd.
I2C pulled up with two 2k2 resistors.
Can read and write a I2C EEPROM with I2CREAD and I2CWRITE without problems, so I think the problem is solely on the MPC23016 side.
I'm first trying only to use half of it, that is only P1 now.
The pins on P1 are pulled up with 10k each.
The code is like this:
1)
DEFINE i2c_hold 1
deviceIO con $40 ' MCP23016 address
GP0 con $00 ' port GP0 all in
GP1 con $01 ' port GP1 all in
OLAT0 con $02 ' Output latch register
OLAT1 con $03 '
IPOL0 con $04 ' input polarity normal, not inverted
IPOL1 con $05 '
IODIR0 con $06 ' all in = 1
IODIR1 con $07 ' 00111011 down=0,up=1,valoT=3,valoE=4,On/Off=5
INTCAP1 con $09 ' read-only, Interrupt Captured Value
INTCAPbyte var byte ' interrupt capture reg for buttons
IOCON1 con $0b '
I2Cbyte var byte
IOEbyte var byte
2)
I2Creg = OLAT1 : I2Cbyte = $ff : gosub writeIOExtender: pause 20
I2Creg = IODIR1 : I2Cbyte = $7f : gosub writeIOExtender: pause 20
I2Creg = GP1 : I2Cbyte = $7f : gosub writeIOExtender: pause 20
3)
I2Creg = GP1 : gosub readIOExtender' to IOEbyte
LCDOUT HEX2 IOEbyte
4)
writeIOExtender:
i2cdevice = deviceIO
I2CWrite SDA,SCL,i2cdevice,I2Creg,[i2cbyte],error
return'from writeIOExtender
'--------------------------------------------------
readIOExtender: ' to IOEbyte
i2cdevice = deviceIO
I2Cread SDA,SCL, i2cdevice,I2Creg,[IOEbyte],error
return'from readIOExtender
You can read back every register except one (INTCAP). I do not know what fails, read or write or perhaps both, but I do not get back what I wrote, so I do not know which one fails, read or write?
And as you can guess, buttons on GP1 does not com through
It seems not to have any effect which one is first (2), OLAT1, IODIR1 or GP1?
I have also the error trap if no ack received (NAK) but it jumps not there!
Can anyone see what is wrong?... Thank you in advance ...![]()
Bookmarks