niak niak
New Member
- Total Posts : 10
- Reward points : 0
- Joined: 2014/07/01 23:42:41
- Location: 0
- Status: offline
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.
|
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)
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.
To get a useful answer, always state which PIC you are using!
|
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)
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.
|
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)
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 ?
|
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)
Yeah, I guess it has to be done by releasing the I2C module and using the pin as a simple I/O.
|
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)
As Dario said. Do it manually.
To get a useful answer, always state which PIC you are using!
|
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)
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.
|
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)
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.
|
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)
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
|
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)
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!
To get a useful answer, always state which PIC you are using!
|
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)
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.
|
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)
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:
|
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)
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: 
No that's not that  I prefer PICs over them, as far as I could see...
|
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)
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: 
No that's not that  I prefer PICs over them, as far as I could see...
|
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)
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...
|
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)
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  just my opinion
|
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)
DarioG ... Of course it does work just my opinion
...and the opinions of those with a great depth of experience should always be valued! cool: [8)]
|