PCF8575 Does not work with my code....


+ Reply to Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default PCF8575 Does not work with my code....

    The all 3 addr pins are connected to GND, which, according to the manual, should give write address of 64. However, it has zero response to my code. Wiring is correct and ports are configured properly. Anyways, here's the complete code - I'm just trying to enable and disable all outputs at same time each 2 seconds.

    Code:
    ;----[16F1937 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1937"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_ON                 ; Program memory code protection is enabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_ON               ; Internal/External Switchover mode is enabled
    cfg1&= _FCMEN_ON              ; Fail-Safe Clock Monitor is enabled
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _VCAPEN_OFF            ; All VCAP pin functionality is disabled
    cfg2&= _PLLEN_OFF             ; 4x PLL disabled
    cfg2&= _STVREN_ON             ; Stack Overflow or Underflow will cause a Reset
    cfg2&= _BORV_19               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    
    'nixie led clock electronics direct drive
    
    
    DEFINE LCD_DREG PORTC  
    DEFINE LCD_DBIT 4  
    DEFINE LCD_RSREG PORTD  
    DEFINE LCD_RSBIT 6  
    DEFINE LCD_EREG PORTC  
    DEFINE LCD_EBIT 3  
    DEFINE LCD_BITS 4  
    DEFINE LCD_LINES 2  
    DEFINE LCD_COMMANDUS 1500  
    DEFINE LCD_DATAUS 200
    DEFINE ADC_BITS 10       ' Set number of bits in result
    DEFINE ADC_CLOCK 3     ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds 
    
    
     
    ADCON1=%11110011 'enable adc internal reference and justify
    FVRCON=%11001111   'set internal reference to 4.096V
    OSCCON=%01110101  'SET INTOSC TO 8MHZ
    ANSELE=%00000000 'enable adc input porte.2
    ANSELA=%00000000 'disable ADC on A
    ANSELB=%00000000 'disable ADC on B
    ANSELD=%00000000 'disable ADC on D
    TRISC=%00000000 'set PORTC as output all
    TRISD=%00000000 'set PORTD as output all
    TRISB=%00000000 'set PORTB as output all
    TRISA=%00000000 'set PORTA 2 as input, others as output
    TRISE=%00000000  'set PORTE as output all
    WPUB=%00000000 'DISABLE B PULL UPS
    OPTION_REG=%100000000 
    LCDCON=%00000000  'disable LCD controller pins
    LCDSE0=%00000000
    LCDSE1=%00000000
    LCDSE2=%00000000
    
    
    DEFINE OSC 8 'set oscillator speed  
    
    
    
    
    SCLM VAR PORTC.7: SDAM VAR PORTC.0  'pcf pins
    
    
    drk:
    I2CWRITE SDAM,SCLM,%01000000,0,[%11111111,%11111111] 'enable outputs
    pause 2000      
    I2CWRITE SDAM,SCLM,%01000000,0,[%00000000,%00000000] 'disable outputs
    pause 2000
    
    
    goto drk
    Any ideas?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Possibly one of the address lines is dry joint so wrong address.

    Found this on forum which could be useful

    https://www.picbasic.co.uk/forum/sho...C-Ping-program

  3. #3
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Commands to the PCF should be an even number of bytes (one for each port), and you seem to be showing 3.
    What's the extra byte after the address?

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    I tried to "bruteforce" all possible address locations - no change.

    The extra byte is write statement, as said in datasheet?

    Name:  writebit.jpg
Views: 266
Size:  284.6 KB

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    PBP handles the read write bit if I remember correctly, leave your 0 out

    this is my code

    ADDR=78 PORTBYTE IS VALUE FOR PORTBITS

    i2cwrite sda,scl,ADDR,PORTBYTE 'ENSURE ALL OFF ON POWER UP

    So I think your code should be

    I2CWRITE SDAM,SCLM,%01000000,[%11111111,%11111111] 'enable outputs

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Meant to have said my code is for the 8 port version, the 16 port version would have another byte added after, as you have got.

    "The extra byte is write statement, as said in datasheet?"

    Your extra byte is a bit not byte.
    Last edited by aerostar; - 22nd October 2023 at 06:39.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Yes, with 8574 I also had no issues....

  8. #8
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    So I think your code should be

    I2CWRITE SDAM,SCLM,%01000000,[%11111111,%11111111] 'enable outputs
    That looks correct to me (an even number of bytes, one for each port), and matches the datasheet shown in post #4.

  9. #9
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    I think there is a hardware issue.
    That code works with standalone module with PCF8575. But does not work with the chip directly soldered to my PCB, so I will swap the IC today later and see, if there's any difference.

  10. #10
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    I figured out the reason, and it is not the code.
    For some reason, PCF8575 can't drive ULN2803.
    When I run it alone, outputs change as they should do
    but when I connect output to ULN2803, output voltage of PCF8575 changes only from 0 to 0.6 volts and ULN2803 does not open.

  11. #11
    Join Date
    Feb 2013
    Posts
    1,078


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Solved.
    Output current of PCF8575 is not enough to drive ULN2803, so I had to add 2.2K pull-up resistors, and now it works just fine.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    It makes no sense. From datasheet, page 7 and figures 6 and 10, seems that the 8575 can drive more than 25mA.

    I am sure that ULN needs much less than that. Maybe you have a faulty chip? Be very careful with static discharge (ESD) problems.

    Ioannis

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    It makes no sense. From datasheet, page 7 and figures 6 and 10, seems that the 8575 can drive more than 25mA.
    no , it can sink 25mA ,source 300uA

    Name:  pcf8575.jpg
Views: 190
Size:  191.6 KB
    Warning I'm not a teacher

  14. #14
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Correct! But what about the charts on page 7?

    Ioannis

  15. #15
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    I measured short circuit current of PCF8575 outputs. It is roughly 0.16mA.

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Correct! But what about the charts on page 7?
    perhaps you should write to them , the graphs in figures 8,9 and 10 are questionable . perhaps the scale should be uA not mA
    Warning I'm not a teacher

  17. #17
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Quote Originally Posted by CuriousOne View Post
    I measured short circuit current of PCF8575 outputs. It is roughly 0.16mA.
    The ULN2803 needs at least 0.35mA, so practically 8575 cannot drive it with enough current.

    Quote Originally Posted by richard View Post
    perhaps you should write to them , the graphs in figures 8,9 and 10 are questionable . perhaps the scale should be uA not mA
    Seems the datasheet has many errors...

    Ioannis

  18. #18
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Yes it has problems pulling it up, but it has no problems pulling it down, so I added 2.2K resistor from input of ULN to +5V and now it can be controlled with PC8575.

  19. #19
    Join Date
    Feb 2023
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    Unless you need I2C for comm, why not use something like a UCN5842 and run with shiftout? I have used these for at least 10 years...

  20. #20
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PCF8575 Does not work with my code....

    I need space saving package, but still solderable by hand, and 16 outputs and low price
    These UCNs are large (not available in TSSOP package) and have only 8 outputs....

Similar Threads

  1. Code doesn't work on 16F648A
    By Mr_Joe in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st September 2018, 22:09
  2. Is anyone willing to work with me to rewrite some code?
    By Ramius in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th June 2017, 17:23
  3. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  4. Why doesn't this servo code work?
    By artswan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th December 2009, 22:18
  5. Why doesn't my code for 18f452 work on 18f252?
    By senojlr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2005, 02:42

Members who have read this thread : 19

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