• AVR Freaks

Hot!I2C SCL invert after changing SSP1ADD (lower bitrate)( PIC16F1779 )

Author
picmaster75
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2018/09/21 03:45:11
  • Location: 0
  • Status: offline
2019/03/29 03:35:51 (permalink)
0

I2C SCL invert after changing SSP1ADD (lower bitrate)( PIC16F1779 )

Dear all,
 
The SCL line seems to invert when i just change the bitrate by changing the SSP1ADD register from 0x4F to 0x90. Does anyone knows how this is possible? When SSP1ADD = 0x4F (100 kb/s), then I2C works like expected and signal levels are as expected.
 
in i2c.c line 142 i have these 2 lines
SSP1ADD = SSP_ADD;
//SSP1ADD = 0x90;
All i do is enabling disabling both lines , which give me a different scope image.
 
I could work at 100 kb/s, but want to know the device 100% and know why this happens at lower speed .
 
* UPDATE
i have write a loop where i increase SSP1ADD every 100ms, to see at which value it go wrong. At value 0x6E and above the SCL line goes inverterd, and it restores again when SSP1ADD is between 0x06 and 0x6E
 
 i'm using PIC16F1779 ...
 
Thanks in advance 
Steve
post edited by picmaster75 - 2019/04/10 05:59:37

Attached Image(s)

#1

7 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9939
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 03:52:23 (permalink)
    +1 (1)
    The code mentions a PIC12F1822. Is that what you are actually using?
     
    #2
    picmaster75
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2018/09/21 03:45:11
    • Location: 0
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 03:58:24 (permalink)
    0
    Sorry, i'm using PIC16F1779
    #3
    qhb
    Superb Member
    • Total Posts : 9939
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 04:02:44 (permalink)
    +1 (1)
    I am very suspicious of this line
        SSP1CON2bits.PEN = 1;  // clear bus

    It's obviously trying to send a STOP condition, but that shouldn't be attempted BEFORE you have written the baud rate to the SSPADD register.
     
    I'm even more suspicious of this line
        SSP1CON2bits.PEN = 0;  // clear bus

    Users cannot clear that bit, it's cleared by the hardware when the STOP condition finishes sending.
     
    Also, what do these functions do?
        I2C_ENABLE_RESET();
    and
        I2C_DISABLE_RESET(); // enable I2C
    I assume they are defined in i2c.h which you did not post.
     
     
     
    #4
    picmaster75
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2018/09/21 03:45:11
    • Location: 0
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 05:37:56 (permalink)
    0
    Thanks for the response !

    SSP1CON2bits.PEN = 1; and
    SSP1CON2bits.PEN = 0;  
    are added after i see the problems in an attempt to solve them, i agree they should not be added at all.
    When i remove them the problem stays.
    It even gets worse, the I2C is fine until 0x6E is written to SSP1ADD , then the SCL inverts like before, but once SSP1ADD  overflows 0x01, 0x02 .... the I2C bus does not recover, which it did
    when adding those PEN lines in code.

    I2C_ENABLE_RESET(); is a line to the RST line of PCA9538BS , that basically resets the chips thats attached to the i2c bus.


    #5
    qhb
    Superb Member
    • Total Posts : 9939
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 13:40:01 (permalink)
    +1 (1)
    picmaster75
    It even gets worse, the I2C is fine until 0x6E is written to SSP1ADD , then the SCL inverts like before, but once SSP1ADD  overflows 0x01, 0x02 .... the I2C bus does not recover, which it did
    when adding those PEN lines in code.



    Get rid of those PEN lines. They are wrong, and if anything are just trying to obscure the original problem.
    The code as you presented it would essentially be starting a STOP cycle, then changing the baud rate in the middle of the cycle, which could cause all sorts of mayhem.
     

    I2C_ENABLE_RESET(); is a line to the RST line of PCA9538BS , that basically resets the chips thats attached to the i2c bus.

    What EXACTLY is the code in that macro?
    Is it addressing the pin via a LATx register (as it should) rather than a PORTx register?
     
    ARRRGH. I see you changed your original post after I answered it. Please DON'T do that.
    It gets incredibly confusing when the answers apply to a question that no longer exists. Add new information in new posts, which also means anyone following this topic gets notified that you have updated it.
     
     
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 17230
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/03/29 14:35:04 (permalink)
    +1 (1)
    Are you disabling the MSSP before changing the Baud rate?
    #7
    picmaster75
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2018/09/21 03:45:11
    • Location: 0
    • Status: offline
    Re: I2C SCL invert after changing SSP1ADD (lower bitrate) 2019/04/10 05:57:07 (permalink)
    0
    Sorry for the later response, i solved the problem by creating a software I2C driver(bitbanging), but lets try to figure out if there is an hardware issue in this PIC, for the sake of everyone that encounter the same problem.
    In my testcode i have disabled MSSP before setting the baud rate, and got rid of all PEN manipulations.
     

     
     
     
    while(1)
    {
    bresult = PCA9538_SetReadMode();
    if(!bresult)
    ALIVE_LED_SetLow();
    else
    ALIVE_LED_SetHigh();
    SSP1CON1bits.SSPEN =0;
    SSP1ADD = varADD++;
    SSP1CON1bits.SSPEN =1;
    __delay_ms(100);
    }

     
      
    But the problem stills occure , now the I2C works till SSP1ADD  = 0x67, then when it overflows and come back in the "valid" range, the I2C do not recover (due to the removing of the PEN manipulation).
     
    Anyway, i dont expect that I2C not work with a lower baudrate , if i try directly at low baud rate (without the sweeping testcode), then I2C don't work at all. It only works at high baudrates.
     
    I2C_ENABLE_Reset() contains this MCC code : do { LATAbits.LATA2 = 0; } while(0)
    The changed i2c driver is attached. (PEN removed)
     
    Any idea?
     
     
    post edited by picmaster75 - 2019/04/10 06:03:56
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5