[I2C][Arduino as Slave]Hang-free alternative to wire

I'm working on a robot, with an raspberry Pi 3 as I2C master and 8 Atmega328P (the same as on the Uno boards, with bootloader) as I2C slaves.

At the beggining, everything works fine, but over the time, the different Arduinos start to hang. As far as I understand (and have seen on another project wit only one arduino as slave and a Jetson as master), the wire.h library has some infinite loops, waiting for some events that according to the I2C protocol are sure to happen. However, if there is some noise/too long cables/... , it can happen that at some point the protocol is not respected, and instead of getting a single failure, the Arduino enters into an infinite loop.

I have found several I2C master libraries that address this issue by adding timeouts for all loops. But I haven't found one for I2C slaves : do you know one?

Thanks a lot in advance
Best regards

PS : on this project, I have about 20cm wires, but passing near motors, so it might explain to get sometimes an error (maybe once each 10 minute for a given arduino). I'm planning to reduce wire length in future when replacing the prototypes PCBs by a manufactured one acting as a shield for the Pi, but that isn't planned for the next few months (I have a lot of things I want to test before ordering the PCBs)

Use shielded cables or twisted pair. Ribbon cable also should work well.

When saying twisted pair, do you mean twisting SDA and SCL? Or twisting SDA with ground and SCL with ground?

For Ribbon cable, could you please explain me why it would improve things.

However, I think it might still be interresting to find a slave library with timeouts (or other protections) : the project is about a robot to explore small passages in caves, so if for whattever reason the arduino hangs, the robot get stuck and there is no way to retrieve it (excepted a t the cost of several days of work, to enlage the passage)

The idea behind twisted pair is the same current flow in each wire but in opposite direction, insensitive to external noise and EM fields. Typically one wire carries the signal and the other one Gnd.

Almost the same for ribbon cable, every other wire is grounded. There existed (exist?) ribbon cables of twisted pairs, with non-twisted sections for press-on (IDC) connectors.

The master always provides the SCL clock, a slave can extend the LOW state for slowing down the transmission. Any device holding down SCL permanently is already in an abnormal state with no regular exit. Eventually an additional Reset signal line could be used to reset all nodes on the bus back into working state?

Thanks for the explanations about twisted and ribbon cables!

For the hangging, I don't think that any device is holding a line (neither SCL nor SDA) down permannently, because all 8 AtMega328P are on the same I2C bus, but they don't stop responding to I2C commands simmultaniously, but each at a different moment. Therefore I suspect that for whatever reason, they enter an infinite loop at some point, which I suspect is due to an I2C error (because I have no explicitly written loops that might result in infinite loops).

That's not very likely if only you have that problem.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.