Shop OBEX P1 Docs P2 Docs Learn Events
I2C PCF8574 doesn't work with PCF8574A; have fix — Parallax Forums

I2C PCF8574 doesn't work with PCF8574A; have fix

Jack HudlerJack Hudler Posts: 6
edited 2009-06-26 23:10 in General Discussion
The PCF8574A is different from the PCF8574 in the slave address.



I've created PCF8574A class that extends PCF8574 which required one minor change in the PCF8574 class.

You must changePFC8574.addr from private to protected.









PFC8574A.Java:

package stamp.peripheral.io;

import stamp.core.*;

/**
·* See base class PCF8574 for additional comments
·*
·* Created PFC8574A - 28 October 2004 Jack Hudler (jack@hudler.org)
·*/

public class PCF8574A extends PCF8574
{
· /**
·· * Create PCF8574A object
·· *
·· * @param bus I2C bus object
·· * @param devAddr Device address (0 .. 7)
·· * @param dirs PCF8574A pin directions (1 = input, 0 = output)
·· */
· public PCF8574A (I2C bus, int devAddr, int dirs)
· {
··· super( bus, devAddr, dirs );
··· this.addr = 0x070 | ((devAddr & 0x07) << 1);
· }

· /**
·· * Create PCF8574A object with private I2C bus.· This method is not
·· * recommended unless the PCF8574A is the only I2C device connected to
·· * the Javelin.
·· *
·· * @param sdaPin I2C serial data pin
·· * @param sclPin I2C serial clock pin
·· * @param devAddr Device address (0 .. 7)
·· * @param dirs PCF8574A pin directions (1 = input, 0 = output)
·· */
· public PCF8574A (int sdaPin, int sclPin, int devAddr, int dirs)
· {
··· super( new I2C(sdaPin, sclPin), devAddr, dirs );
··· this.addr = 0x070 | ((devAddr & 0x07) << 1);
· }
}

Comments

  • mtstormmtstorm Posts: 8
    edited 2009-06-26 21:54
    Hello,
    I think it is better to make it more generic, proposal make an abstract and derice the two chips. the adress calculation differs. If there are more off these family then it will be easy to implement.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-06-26 23:10
    mtstorm,

    Take a look at my I2C classes:
    http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/protocol/i2c/
    and·my memory classes:
    http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/memory/

    With those classes you can define

    static I2CsmDevice DS1307_CHIP = new I2CsmDevice(pinSDA,pinSCL,0xD0|I2Cdevice.ADDR8,64,1,1); //DS1307 rtc, no pagewrite delay
    static I2Cmemory backupRam = new I2Cmemory(DS1307_CHIP,8,56);
    static DS1307 rtc = new DS1307(DS1307_CHIP);
    static I2CsmDevice MC24LC32A_CHIP = new I2CsmDevice(pinSDA,pinSCL,0xA0|I2Cdevice.ADDR16,32,128,53); //MC24LC32A eeprom, 5ms pagewrite delay
    static I2Cmemory ee = new I2Cmemory(MC24LC32A_CHIP,0,4096);
    static I2CsmDevice CF_DATA = new I2CsmDevice(pinSDA,pinSCL,0x40,32767,1,1); //PCF8574
    static I2CsmDevice CF_CONTROL = new I2CsmDevice(pinSDA,pinSCL,0x70,32767,1,1); //PCF8574A

    The I2C and memory superclasses are abstract. Then there are extended classes
    for specific interfaces. With I2Cmemory for example, both the rtc backupram and an eeprom
    use the same read/write methods and are of the same type.
    This means a backup routine simply writes to memory, the main program determines
    what the actual memory is.

    regards peter

    Post Edited (Peter Verkaik) : 6/26/2009 11:18:15 PM GMT
Sign In or Register to comment.