PDA

View Full Version : Reading From a PCF8574



John Abshier
11-01-2006, 07: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

Peter Jakacki
11-01-2006, 08:06 AM
Just a quick note..
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*

John Abshier
11-01-2006, 11:08 AM
Thanks Peter. It works!! 4x20 lcd, 2 led, and 7 buttons on 2 IO lines. I am happy

chandleg
03-18-2011, 10:47 AM
Do you still have the C/C++ code you used to control the spyglass? I've been hacking away at one today, with no luck.