I2CWRITE not writing anything on PIC18F45K80


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,079

    Default I2CWRITE not writing anything on PIC18F45K80

    Hello.
    I have PCF8574 connected to PIC18F45K80.
    The timings and configs are correct, tried to generate some pulses and frequencies are correct.
    Tried just to pull up and down SDA/SCL pins and check result with scope, while having PCF8574 connected - I can see proper pulses on the scope.
    However, when I try to I2CWRITE, I see no activity at all on either SDA or SCL pins, and sure does not work. Adding I2C SLOW does not change anything.

    Here's my code:

    Code:
    #config
    CONFIG RETEN = OFF	
    CONFIG INTOSCSEL = HIGH
    CONFIG SOSCSEL = DIG
    CONFIG XINST = ON	    ;Enabled
    CONFIG FOSC = INTIO1
    CONFIG PLLCFG = OFF
    CONFIG FCMEN = OFF	    ;Disabled
    CONFIG PWRTEN = OFF	    ;Disabled
    CONFIG BOREN = OFF	    ;Disabled in hardware, SBOREN disabled
    CONFIG WDTEN = OFF	    ;WDT disabled in hardware; SWDTEN bit disabled
    CONFIG CANMX = PORTB
    CONFIG MCLRE = OFF
    
    
    #endconfig
    
    
    'OSCTUNE.6 = 1 ; Enable 4x PLL
    OSCCON = %01110000
    ANCON1=0 'DISABLE ADC D3-D2-D1-D0-
    ANCON0=0
    ADCON0=0
    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=%0000000  'set PORTE as output all
    define OSC 16
    DEFINE I2C_SLOW 1
    ADR VAR BYTE
    ADR=$48
    
    
    SDA VAR PORTD.3
    SCL VAR PORTD.2
    
    
    'dfe:
    'high sda
    'pause 1
    'low sda
    'pause 1
    'goto dfe
    
    
    FEDO:
    I2CWRITE SDA,SCL,ADR,[%11111111]
    PAUSE 50
    I2CWRITE SDA,SCL,ADR,[%00000000]
    PAUSE 50
    GOTO FEDO

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,828


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    I think you are missing the control before the address of the I2C commands.

    Also DEFINE I2C_SLOW 1 is NOT needed.

    try this

    Cont = %01000000

    I2CWRITE SDA,SCL,Cont,[%11111111]
    PAUSE 500
    I2CWRITE SDA,SCL,Cont,[%00000000]
    pause 500


    Ioannis

  3. #3
    Join Date
    Feb 2013
    Posts
    1,079


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    And where to put address?
    I have several PCFs....

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,828


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    OK, in the cont constant will be the address. What chip do you have? Is it the "A" type?

    The "A" type needs cont=%0111AAA0

    The plain PCF8574 needs cont=%01000AAA0

    where AAA is the address bits.

    Ioannis
    Last edited by Ioannis; - 13th March 2023 at 20:34.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    provided it is wired correctly and the chip is pcf8574 the original code works just fine
    although technically
    TRISD=%00000000 'set PORTD as output all
    should be
    TRISD=%00001100 'set PORTD

    Name:  k80.jpg
Views: 3738
Size:  224.7 KB
    Warning I'm not a teacher

  6. #6
    Join Date
    Feb 2013
    Posts
    1,079


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    The chips are PCF8574T.
    I have pull up resistors 4.7K and SDA and SCL pins of 3 pcs. PCF chips are in parallel.
    I tried adding that cont variable and changing TRIS for D port pins. Still nothing.
    On the startup, SCL gets high and that's all, there is no activity on these pins.
    But if I run simple high/low statements for those pins, then I can see these pins getting high or low on scope.

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


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    By the way, I have DS3231 hooked to another pins of same CPU.
    It also not working - no activity on SDA/SCL pins while performing I2CREAD.
    So maybe some config error?

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    So maybe some config error?
    if you mean its wiring error or the chips aren't what you say , probably

    schematic ?
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    No, there is no wiring error and when using HIGH or LOW statements, I can pull these pins up and down as normal.
    I mean, maybe there is some config error for 18F, which prevents I2CREAD/I2CWRITE from working?

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    to be clear

    provided it is wired correctly and the chip is pcf8574 the original code works just fine
    Warning I'm not a teacher

Similar Threads

  1. DT_Ints with PIC18F45K80 problem
    By Zapman in forum Code Examples
    Replies: 2
    Last Post: - 20th April 2022, 01:43
  2. Replies: 9
    Last Post: - 27th January 2015, 13:57
  3. PIC18F45K80 runs way to fast.
    By bmoe79 in forum PBP3
    Replies: 3
    Last Post: - 19th December 2014, 13:24
  4. I2CWrite issue
    By robertmark68 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th September 2006, 01:30
  5. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45

Members who have read this thread : 3

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