Shop OBEX P1 Docs P2 Docs Learn Events
Reading Bits from a PCF8574A I/O Expander — Parallax Forums

Reading Bits from a PCF8574A I/O Expander

Alan BradfordAlan Bradford Posts: 172
edited 2009-01-18 17:32 in BASIC Stamp
Hi,
It has been a long time since I did logical operations in Basic 101 at college (35 years), and I cant remember how to do this,
I am using some PCF8574A I/O Expanders with a BS2p.
I am using seperate chips for Input and Output.
I have the I2C commands working. I need to access the data.
I have·3 questions:
1) Once I input the Byte of Data, how·can·I·look at the individual bits? I am reading switch closures.
2) How do I turn on Individual Outputs?
3) The data sheets say I can connect 16 devices but they only have 3 addressing bits. How do·I address the second group of 8 Chips?


Thank You,
Alan Bradford
Plasma Technologies
www.plasmatechnologies.com

Comments

  • ZootZoot Posts: 2,227
    edited 2009-01-18 16:20
    Alan Bradford said...
    1) Once I input the Byte of Data, how can I look at the individual bits? I am reading switch closures.

    In Pbasic, you can access bits like this:

    ioByte VAR Byte
    ' set a bit
    ioByte.BIT0 = 1
    ' read a bit
    IF ioByte.BIT2 = 1 THEN
       HIGH 0
    ENDIF
    'etc
    
    


    If you need to access bits "dynamically" (i.e. as pseudo array) you can do it like this:
    i VAR Byte
    ioByte VAR Byte
    FOR i = 0 TO 7 ' loop through 8 bits
       IF ioByte.BIT0(i) = 1 THEN
         ' do something
       ENDIF
    NEXT
    
    


    Alan Bradford said...
    2) How do I turn on Individual Outputs?

    See above. If you are dumping the byte(s) to the I/O expander you can set bits as you need, then dump the byte to the peripheral chip.
    Alan Bradford said...
    3) The data sheets say I can connect 16 devices but they only have 3 addressing bits. How do I address the second group of 8 Chips?

    I just checked the data sheets -- I don't see any mention of using 16 of these devices on a single I2C bus. Where did you read that? In my reading you would only be able to put 8 of these on a single bus given the addressing schema. You could have TWO I2C busses, with 8 on each... or am I missing something here?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 1/18/2009 6:58:46 PM GMT
  • kelvin jameskelvin james Posts: 531
    edited 2009-01-18 17:03
    Alan

    The PCF8574 and the PCF8574A are the same chips, but each has a different address. So you could use 8 of each on the same bus.

    **
  • Alan BradfordAlan Bradford Posts: 172
    edited 2009-01-18 17:32
    Hi Guys,
    That was just what i was looking for.
    Thanks for the help.
    Alan Bradford

Sign In or Register to comment.