Shop OBEX P1 Docs P2 Docs Learn Events
Cannot get the PCF8574 working. — Parallax Forums

Cannot get the PCF8574 working.

jtilghmanjtilghman Posts: 67
edited 2013-04-16 17:18 in Propeller 1
Cannot get the PCF8574 working.

I have it connected and working with a Arduino. I then hook it up to the Prop and I can't seem to get it to work.

I am using http://obex.parallax.com/objects/271/ driver.

Not sure what to try, I have a logic analyzer connected and the data coming across the bus looks different from the prop than from the arduiino.

I am using 20h as the address, but i have tried others. The driver says that it is based on another driver that is in the OBEX but for some reason I cannot find any other driver but that one.

Here is the code I am using:
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  
  SCL  = 15        'PCF8574 Serial ClK line
  SDA  = 14       'PCF8574 Serial DATA line
  ADDR = 20      'PCF8574A I2C Address (A0, A1, A2 all pulled low)

OBJ
  IO     : "PCF8574_Driver"

PUB Main

  IO.Set_Pins(SCL, SDA)
  IO.Initialize

REPEAT    
  IO.OUT(ADDR, 001111)
  IO.OUT(ADDR, 000000)
  IO.OUT(ADDR, 001111)
  IO.OUT(ADDR, 000000)
  IO.OUT(ADDR, 001111)
  IO.OUT(ADDR, 000000)
  IO.OUT(ADDR, 001111)
  IO.OUT(ADDR, 000000)
  IO.OUT(ADDR, 001111)

{{

If there is any information I left out or anything to try, please let me know.

My goal is to be able to add some more I/O to the prop I am trying to use on my robot. :)

Thanks,
JT

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-04-10 16:21
    jtilghman wrote: »
    Cannot get the PCF8574 working.

    I have it connected and working with a Arduino. I then hook it up to the Prop and I can't seem to get it to work.

    I am using http://obex.parallax.com/objects/271/ driver.

    Not sure what to try, I have a logic analyzer connected and the data coming across the bus looks different from the prop than from the arduiino.

    I am using 20h as the address, but i have tried others. The driver says that it is based on another driver that is in the OBEX but for some reason I cannot find any other driver but that one.
    <snip>
    If there is any information I left out or anything to try, please let me know.

    My goal is to be able to add some more I/O to the prop I am trying to use on my robot. :)

    Thanks,
    JT

    Not sure about the driver but it should work however I recently used a PCF8574 but since it had to run from a 5V supply I put a red LED in series with the supply to lower the logic thresholds so that it would work with the Prop. The chip can work directly from 3.3V though. You do have pullup resistors on the SDA and SCL, right?
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-10 17:34
    Well when I run it on the prop, it is running at 3.3 and on the arduino its 5v.

    Yes I have pull ups when using it either.

    As to the driver, its all I could find. Was thinking of trying 12 blocks to talk to it, but haven't got about how to use 12 blocks yet.

    Just trying to turn some LEDs on and off. How hard could it be. lol :)
  • RaymanRayman Posts: 14,665
    edited 2013-04-10 17:46
    I've got some notes on this here:
    http://www.rayslogic.com/propeller/programming/i2c/i2c.htm

    BTW: I'd highly recommend upgrading to the newer PCA9554...
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-04-10 18:02
    jtilghman wrote: »
    Well when I run it on the prop, it is running at 3.3 and on the arduino its 5v.

    Yes I have pull ups when using it either.

    As to the driver, its all I could find. Was thinking of trying 12 blocks to talk to it, but haven't got about how to use 12 blocks yet.

    Just trying to turn some LEDs on and off. How hard could it be. lol :)

    If you had Tachyon Forth loaded then it would be very very easy, you would have it running in under 30 seconds. Less since you could copy and paste this code:
    [FONT=courier new]pub ReadIO ( -- data )
        I2CSTART $41 I2C! 0 I2C@ I2CSTOP
        ;
        
    pub WriteIO ( data -- )
        I2CSTART $40 I2C! I2C! I2CSTOP
        ;
    [/FONT]
    
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-04-10 18:50
    I wrote a very simple object for the PCA8574 which works in an I2C LCD. After a quick look at the data sheets, the only difference between the two devices seems to be output current capability. Give this a try.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-10 20:09
    Hey JonnyMac, Thanks.. I will try this tonight and let you know..

    Hey Rayman: Why would I want that one over this one ? and I am just trying to use what I have already.

    Hey Peter, I might have to give that a try. Still trying to wrap my head around SPIN.

    Thanks,
    jt
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-10 21:29
    Hey JonnyMac, I couldn't get it working with your code.

    I will post it here, I most likely haven't got it setup correctly.
    con
    
      RX1 = 31                                                      ' programming / terminal
      TX1 = 30
      
      SDA = 15                                                      ' eeprom / i2c
      SCL = 14
    
    
    con
    
      WR_8574 = 00_000_0
      RD_8574 = 00_000_1 
      
    
    obj
    
      i2c : "jm_i2c"
      
    
    var
    
      byte  devid                                                   ' PCF8574 address
    
    
    pub start(sclpin, sdapin)
    
    '' Start PCA8574 object
    '' -- sclpin and sdapin define i2c buss
    '' -- addr is device addres, 0 to 7
    
      i2c.setupx(sclpin, sdapin)                                    ' connect to buss
    REPEAT
      write(000000, 00000000)
      write(000000, 00001010)
      write(000000, 00000101)
      write(000000, 00001010)
      write(000000, 00000101)
      write(000000, 00001010)
      write(000000, 00000101)
      write(000000, 00001111)
      write(000000, 00000000)
    
    
    pub write(addr, b)
    
    '' Write byte b to PCA8574 port
    
      i2c.start
      i2c.write(WR_8574 | (addr << 1))
      i2c.write(b)
      i2c.stop
    
    
    pub read(addr) | b
    
    '' Read port bits from PCA8574
    
      i2c.start
      i2c.write(RD_8574 | (addr << 1))
      b := i2c.read(i2c#ACK)
      i2c.stop
    
      return b
    
    
    dat
    
    {{
    

    Sorry if I didn't get it correct, I still learning SPIN.

    Thanks for trying.

    JT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-04-10 21:33
    jtilghman wrote: »
    Hey JonnyMac, Thanks.. I will try this tonight and let you know..

    Hey Rayman: Why would I want that one over this one ? and I am just trying to use what I have already.

    Hey Peter, I might have to give that a try. Still trying to wrap my head around SPIN.

    Thanks,
    jt

    No problems, but unlike SPIN it happens to be interactive so all you need to do is load Tachyon onto your board and connect up a serial terminal at 230400 baud (unless you change the default). Being interactive you can quickly spot the problem for instance by making sure that the "command" I2CBUS detects it. Ya just gotta try it.

    Propeller .:.:--TACHYON--:.:. Forth V21130404.1000
    
    NAMES:  $60F3...743B for 4936 (20200 bytes added) with 22407 bytes free
    CODE:   $0000...2B2A for 6114 (0413 bytes added) with 21718 bytes free
    CALLS:  0587 vectors free
    
    AUTORUN BOOT
    MODULES LOADED: 
    298D: ANSI.fth            ANSI control sequences - 130303.2100 
    1880: EXTEND.fth          Primary extensions to TACHYON kernel - 130316.1600 
    ----------------------------------------------------------------
    I2CBUS 
    Fast Device at 0002  03 00 00 00 00 00 00 00 
    Fast Device at 00A0  B4 C4 04 6F 44 10 00 20 
    Fast Device at 00A2  00 80 B8 C0 98 B1 BB 23  ok
    
    
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-10 22:05
    As soon as I get one of my props to match your config, I will give it whirl.

    I use a program that I found in one of the other threads here called I2CSCAN and it can see the EXPANDER just fine.

    Here is the output:
    Scanning I2C Bus....
    Scan Addr :  000000 00100000,  ACK
    i2cScan found 1 devices!
    

    So it kind of works. :(

    Thanks,
    JT
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-15 11:07
    Rayman wrote: »
    I've got some notes on this here:
    http://www.rayslogic.com/propeller/programming/i2c/i2c.htm

    BTW: I'd highly recommend upgrading to the newer PCA9554...

    I ordered some PCA9554's, they will be here today.

    I will let you know how they do.

    Thanks,
    JT
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-04-15 11:28
    Hey JonnyMac, I couldn't get it working with your code.

    Two things: You clobbered my working object, and you completely missed the mark in usage. Also, even if you had done it correctly you may have not seen things working because you have no delays between your pattern outputs.

    Here's a partial listing that should be helpful. Download and overwrite my object (to restore it to working order) and then give this code a try.
    con
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000                                          ' use 5MHz crystal
    
    
    obj
    
      iox : "jm_pca8574"
      
    
    dat
    
    Pattern         byte    %00000000
                    byte    %00001010
                    byte    %00000101
                    byte    %00001010
                    byte    %00000101
                    byte    %00001010
                    byte    %00000101
                    byte    %00001111
    
    
    pub main | idx
    
      iox.start(14, 15)
    
      repeat
        repeat idx from 0 to 7
          iox.write(%000, Pattern[idx])                             ' update outputs
          waitcnt(cnt + (clkfreq >> 2))                             ' 1/4s (250ms))
    

    Scan Addr : 000000 00100000, ACK

    Are you sure you have a PCF8574? According to the documentation, the address should be %0100_AAA_0 -- that is, with $4 in the upper nibble, not $2 as your scan indicates.
  • jtilghmanjtilghman Posts: 67
    edited 2013-04-16 13:26
    Hey JonnyMac,

    I am sorry I messed up calling the object. I am still new to SPIN and for the most part it seems to makes, not all of it tho.

    As to the PCF8574, the chip came from DigiKey and says its NXP PCF8574 , I also just got some PCA9554 as, but no luck with them either.

    I will try and make your code snippet from the last post work and update on my progress.

    I thank you for your time and effort trying to help me, am I just a little slow at some of these things.

    Thanks,
    jt
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-04-16 17:18
    If you want to play with hardware then getting interactive is way more fun. There's no need for a I2C driver as the same Tachyon cog can run at full I2C speeds. That same code in Tachyon along with the PCF8574 interface is simply:

    [FONT=courier new]$40    == PCF8574                        \ Chip's I2C address (8-bit format)
    
    pub ReadIO ( -- data )
        I2CSTART PCF8574 1+ I2C! 0 I2C@ I2CSTOP
        ;
        
    pub WriteIO ( data -- )
        I2CSTART PCF8574 I2C! I2C! I2CSTOP
        ;
    
    TABLE Pattern [noparse]
        %00000000 | %00001010 | %00000101 | %00001010 | 
        %00000101 | %00001010 | %00000101 | %00001111 |
    [/noparse]
    pub main
      I2CSTOP                            \ Init the I2C pins just in case
      BEGIN
        0 8 ADO Pattern I + C@ WriteIO #250 ms LOOP            \ cycle through 8 patterns 
        ESC?                            \ oontinue looping until an escape key is pressed
      UNTIL
      ;     
    
    [/FONT]
    
Sign In or Register to comment.