how to get PCF8574 and PIC16F876A work together


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Location
    Porto - Portugal
    Posts
    28

    Default how to get PCF8574 and PIC16F876A work together

    Hi, can anyone help me?

    I need to expand the i/0 capabilities of a PIC16F876A and the usual (I supose) is to use an i/o expander like the Philips PCF8574 (or other Manufacturer/Type).

    As I am a newcomer to the art of programing microcontrollers I've searched the forum for instances of I2C* and found a lot of usefull information on how to use I2C comunication and related devices.

    However, when I tried to use "the real stuff" I found myself in a dead end and the reason probably resides in the errors of understanding the Philips datasheet about PCF8574 and/or the lack of programming skills.


    Only for test purposes I've tried to "marry" the PIC16F876A and the PCF8574 with a small PBP program intended to switch on and off 8 leds, PCF has latched outputs, the code looks like this:

    DEFINE OSC 10
    ADCON1=7
    DEFINE I2C_SLOW

    TRISA=%00000001

    SCL VAR PORTA.1 ' 4k7 pull-up
    SDA VAR PORTA.0 ' 4k7 pull-up


    start:

    I2CWRITE SDA,SCL,%01000000,[%11111111] leds ON
    PAUSE 5000

    I2CWRITE SDA,SCL,%01000000,[%00000000] 'leds off
    pause 5000

    goto start

    end


    Ok! At this moment you can lough if after reading the code above I think it could work!


    I´ve watched the PIC pins with my osciloscope and found that each five seconds both SDA and SCL generates a " signal burst" to ground.

    I realise that something is wrong with the code (or the way I'm missing something in the PCF datasheet) because the leds remain as they came from the store and even when I disconect the leds I found (with osciloscope) that the logic level present at PCF i/o pins is somewhere between low and high and at each 5sec they reach high logic level.

    Sorry about my english, thanks for reading
    NOMADA
    nomada

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    before i read datasheet, can you modify your code as this
    Code:
    DEFINE OSC 10 
    ADCON1=7 
    
    SCL    VAR PORTA.1 ' 4k7 pull-up
    SDA    VAR PORTA.0 ' 4k7 pull-up
    Cont   VAR BYTE
    Cont = %01000000
    
    start:
    
    I2CWRITE SDA,SCL,Cont,[%11111111] 'leds ON
    PAUSE 5000
    
    I2CWRITE SDA,SCL,Cont,[%00000000] 'leds off
    pause 5000
    
    goto start
    • 1. I remove I2C_SLOW define... not sure you need it.

      2. i remove TRISA define. SDA is suppose to be bidirectionnal (if you read/write from external device), but you assign PORTA.0 (SDA) as an input so, when you trying to write to external, it's not sure that it will work as you request...

      3. I add specific Variable for the control byte. It refer to the PBP book and this thread http://www.picbasic.co.uk/forum/show...hlight=I2CREAD

      4. Also, be sure you didn't swap SCL & SDA pins too. If it doesn't work, some registers might be initialize... let me know, i'll take a look to datasheet.
    Last edited by mister_e; - 14th December 2004 at 00:55.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2004
    Location
    Porto - Portugal
    Posts
    28


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks mister_e

    I implemented your sugestions but even though the PCF refuses to work.

    I also started to suspect of PCF sample chip I received from Philips distributor, because is not normal the logic level never reaches 0 (ground) even without pull-up resistors.

    So... I bought a new chip and... VOILÁ

    I suppose that sample chips are like PORT WINE, some are good and some aren't.

    Sometimes, no matter how much time you have spent in you life dealing with electronics,always keep forgetting that it may be some problem with materials. I need to pay more attention to this kind of things.

    Once again thanks a lot for your kind assistance and ... please accept my season's greetings

    NOMADA
    nomada

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi nomada,

    great to know everything's working good now. Yep it happen sometimes some SAMPLES can be burn or defect... as new one too. We often think, and it's normal, news part will work... This is why i always buy more than 5 to be sure of everything... but it can be also a batch problem... i never see it for now but, for sure it can happen.

    Pleas accept my season's greeting, merry christmas, happy new year, Joyeux Noel, all the best for the years to come, etc
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. troubles using more than one PCF8574
    By maus in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th July 2007, 19:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts