How to test an atmega (arduino) i2c network

arduinocommunicationi2c

First of all sorry for my bad English and for this "theoretical" question on how is the best way to do things. I'm just out from university and no-one ever told me how problems can be resolved in a practical way.

I'm trying to develop a network of 4 atmega (I'm using Arduino platform), 1 master and 3 slaves. they are communicating via i2c.

I'm looking for a smart way to test it. right now my debug is happening via serial protocol: i have some

Serial.println(...);

and I'm reading them plugging the Arduinos via USB and reading serial incoming messages with serial monitor in Arduino IDE.

What i am doing now is:

  1. Coding slaves having a test program (one for each slave) in the master (powered with a normal power supply).
  2. When I'm "sure" that the slave is OK, unplug the USB of the slave, plug the master, coding the master.
  3. Do this for each slave.
  4. Pray.

This workflow has a lot of problems; it is a blind communication. When I'm working on the master, I don't really know what is happening on the slaves, and vice-versa. Then, if one Arduino crash causes the master to crash (because the I2C protocol does not provide for the fact that one slave does not respond or it is switched off) and I have to reset all slaves (I'm doing that by switching off the power supply of all slaves).

One more problem: Some slaves need real-time operation with stepper motors, and if a motor is running and some interrupts of I2C protocol library Wire.h occur (and this is happening each time the master require some message from the slave, I think), it eventually can happen while the motor is running and this cause the motors' movement (that must be as linear as possible) to be "trottered". To avoid this, I have only one-way communication: The slaves only receive commands. I don't know if this is the best solution but seems to work.

The blind one-way communication, the repeated plugging and unplugging of USB, plugging and unplugging the power supply and pressing reset buttons is making me feel stupid. Until now, I have done software development with IDE (Eclipse) that provides debug. If I have a some threads to be synchronized, I can have prints or whatever that make life simpler, and with software I'm doing unit testing that gives me a good tool for isolating the bug. Now with the Arduinos net, when something goes wrong, I don't have any idea how to find where is the problem. This is my first hardware network, and it is frustrating.

I need some advice on figure out a smart workflow, having a nice way to test my system, and to feel myself a coder.

Best Answer

You can probe and monitor the bus using BusPirate. This way you can see what is happening on the bus and will help you debug the issues.

Here is a video demonstrating i2c bus scan.
It can also be used as a I2C analyzer as demonstrated in this video.