Reading From a PCF8574
John Abshier
Posts: 1,116
I am writing an object to interface with a Spyglass Control Panel.· Writing to the lcd and leds is OK.· I am stumped on how to read the buttons.· PBasic was simple:
I2CIN 0, ButtonsAddr, $FF, [noparse][[/noparse]ButtonCode]
ButtonAddr = $40· The $FF is optional since the PCF8574 doesn't use an address within the device.
The C code just calls an I2C read routing with an address of $40
This is my attemp in Spin
·nodeAddr = $00, PCF8574_I2C_BASE_ADDR = $40
I always get a return value of $FF
I2CIN 0, ButtonsAddr, $FF, [noparse][[/noparse]ButtonCode]
ButtonAddr = $40· The $FF is optional since the PCF8574 doesn't use an address within the device.
The C code just calls an I2C read routing with an address of $40
This is my attemp in Spin
Pub pcf8574Read(nodeAddr) : data ' // read data I2C.i2cStart I2C.i2cWrite(PCF8574_I2C_BASE_ADDR+(nodeAddr<<1)|1,8) I2C.i2cStart data := I2C.i2cRead(1, 8) I2C.i2cStop return
·nodeAddr = $00, PCF8574_I2C_BASE_ADDR = $40
I always get a return value of $FF
Comments
You should be writing address $41 then receive an ack from the slave then simply read the data. You are issuing a start condition before the read data (wrong).
*Peter*