• AVR Freaks

I2C Bus error handling

Author
niak niak
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2014/07/01 23:42:41
  • Location: 0
  • Status: offline
2014/08/12 02:19:54 (permalink)
0

I2C Bus error handling

Hello,
I have a functionnal I2C Bus except sometimes i have a lockup problem (one of the slave holds SDA low).
After looking for a solution on different website, I found this :
In this scenario the external slave might be holding SDA low to transmit a 0 (or ACK). In this case it will not release SDA until it gets another falling edge on SCL. Even in this case it's not until it tries to transmit a '1' that it will actually release SDA after seeing SCL fall. The end result is that the bus will hang. If the I2C tries to initiate a new transfer it will hit an "arbitration lost" condition because SDA won't match the address it's sending.
 
A workaround has been reported to work even on these devices. By configuring the I2C for "free data format" and then reading a byte the I2C will immediately start sending clocks to input data (rather than trying to send an address).
So I would like to do so but I have no idea on how to do that. I would be grateful, if you can help me with this issue.
And I am interrested in any possible solution to this problem.
#1

16 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29690
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 02:42:33 (permalink)
    +8 (5)
    Just manually toggle the SCL line low and high nine times at 100kHz or slower, while letting SDA float, and the slave will let go of the bus.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Chris A
    Super Member
    • Total Posts : 864
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 03:05:21 (permalink)
    +2 (2)
    What RIC describes should be part of the startup code of all I2C systems when there isn't a reset line to all slave devices.
    #3
    niak niak
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2014/07/01 23:42:41
    • Location: 0
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 03:28:56 (permalink)
    0
    Thank you for the answer.
     
    But how do you toggle the SCL line using the I2C Library ?
    Maybe it's not possible.
    So I set the pin has an output and toggle it ?
    Or there is an register to modify in order to do so ?
    #4
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 03:37:25 (permalink)
    +1 (1)
    Yeah, I guess it has to be done by releasing the I2C module and using the pin as a simple I/O.

    GENOVA :D :D ! GODO
    #5
    ric
    Super Member
    • Total Posts : 29690
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 03:44:51 (permalink)
    0 (1)
    As Dario said. Do it manually.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    DavidBLit
    Super Member
    • Total Posts : 1585
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 05:39:05 (permalink)
    0
    niak niak
    Thank you for the answer.
     
    But how do you toggle the SCL line using the I2C Library ?
    Maybe it's not possible.
    So I set the pin has an output and toggle it ?
    Or there is an register to modify in order to do so ?




    Try something like this.
    #7
    niak niak
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2014/07/01 23:42:41
    • Location: 0
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 06:06:03 (permalink)
    0
    Ok.
    I am asking myself when I should trigger this reboot ?
    So I have a timer and after a while do the sequence or it's better to do it before every transmission ?
     
    Thank you again for your help.
    #8
    Ian.M
    Super Member
    • Total Posts : 13273
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 06:22:19 (permalink)
    +2 (2)
    You only do it on startup and if the bus has hung.   Start your timer, zero it on every successful I2C operation and when it times out check the bus.  If SCL is high and SDA is low, poll it for longer than the slowest device takes to send a byte.  Any transitions - reset the timer.  No transitions - abort any I2C operations, disable the MSSP (I2C) peripheral, bitbang the 9 SCL: bus reset sequence, wait and check the bus is free then reenable the MSSP in I2C mode

    --
    NEW USERS: Posting images, links and code - workaround for restrictions.
    I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
    #9
    ric
    Super Member
    • Total Posts : 29690
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 07:00:24 (permalink)
    +1 (1)
    You could check SCL and SDA before you start any transaction. They should both be high.
    If SDA is low, then something on the bus is stuck, and you need to issue that sequence.
    If you just try to issue a START sequence, you will get an immediate "collision" error.
    If SCL is low before you start, then you have real problems!

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 15:12:00 (permalink)
    0
    We're having issues in where on a noisy ARM-powered board, MCP2317 stop working. We have knowledge of this fact by being unable to read back a register value, so we do the reset.

    GENOVA :D :D ! GODO
    #11
    DavidBLit
    Super Member
    • Total Posts : 1585
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re: I2C Bus error handling 2014/08/12 16:31:13 (permalink)
    0
    DarioG
    We're having issues in where on a noisy ARM-powered board, MCP2317 stop working. We have knowledge of this fact by being unable to read back a register value, so we do the reset.



    Write to LATx, not PORTx!  Oh, wait... wink: wink
    #12
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: I2C Bus error handling 2014/08/13 02:19:54 (permalink)
    0
    DavidBLit
    DarioG
    We're having issues in where on a noisy ARM-powered board, MCP2317 stop working. We have knowledge of this fact by being unable to read back a register value, so we do the reset.



    Write to LATx, not PORTx!  Oh, wait... wink: wink




     
    No that's not that grin
    I prefer PICs over them, as far as I could see...

    GENOVA :D :D ! GODO
    #13
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: I2C Bus error handling 2014/08/13 02:20:01 (permalink)
    0
    DavidBLit
    DarioG
    We're having issues in where on a noisy ARM-powered board, MCP2317 stop working. We have knowledge of this fact by being unable to read back a register value, so we do the reset.



    Write to LATx, not PORTx!  Oh, wait... wink: wink




     
    No that's not that grin
    I prefer PICs over them, as far as I could see...

    GENOVA :D :D ! GODO
    #14
    DavidBLit
    Super Member
    • Total Posts : 1585
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re: I2C Bus error handling 2014/08/13 05:07:08 (permalink)
    0
    DarioG
    ...
    I prefer PICs over them, as far as I could see...
    ...



    I am very curious as to why.  The peripheral suite is at least comparable (I'm thinking of vendors like ST and Freescale) and the span of the Cortex-M0 at the low end to -M4 at the high (with a relatively consistent instruction set) seems a benefit over the "step-function" changes in architecture through the PIC spectrum.
     
    ...and you're not burdened with artificially crippled compilers...
     
    #15
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: I2C Bus error handling 2014/08/13 06:04:47 (permalink)
    0
    It was an overall "feeling".
    I used Keil environment, and it was more or less ok. I only notice something "funny" but all right.
    There was something strange in the hardware registers, peripherals etc - now I don't remember exactly and the code is on another PC...
     
    Of course it does work Smile just my opinion

    GENOVA :D :D ! GODO
    #16
    DavidBLit
    Super Member
    • Total Posts : 1585
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re: I2C Bus error handling 2014/08/13 06:59:31 (permalink)
    +3 (2)
    DarioG
    ...
    Of course it does work Smile just my opinion



    ...and the opinions of those with a great depth of experience should always be valued!  cool: [8)]
    #17
    Jump to:
    © 2021 APG vNext Commercial Version 4.5