Shop OBEX P1 Docs P2 Docs Learn Events
Reading From a PCF8574 — Parallax Forums

Reading From a PCF8574

John AbshierJohn Abshier Posts: 1,116
edited 2011-03-18 02:47 in Propeller 1
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

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

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2006-11-01 00:06
    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 AbshierJohn Abshier Posts: 1,116
    edited 2006-11-01 03:08
    Thanks Peter. It works!! 4x20 lcd, 2 led, and 7 buttons on 2 IO lines. I am happy
  • chandlegchandleg Posts: 1
    edited 2011-03-18 02:47
    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.
Sign In or Register to comment.