John Abshier
11-01-2006, 06:38 AM
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, [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
I2CIN 0, ButtonsAddr, $FF, [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