Bidirectional communication between 2 Arduinos with I2C? pointers?

Hi all

I wish to implement bidirectional I2C communication between 2 arduinos.

Can anyone give me any pointers?

I plan to create a motor control or perhaps more accurately a steering module which will consist of an AVR chip and a motor control chip.

From the motherboard (the other AVR) I wish to send directional commands as left(degrees, speed), stop(), speed(255), goto(x,y) etc and then let the steerage AVR control the motor controller while the motherboard gets on with other tasks.

Some commands, such as goto or left may require a completed() message being sent to the motherboard. Other unexpected messages such as stall() may need to be sent to the motherboard without prompting. both these examples would interrupt the motherboard and the motherboard should process them. Similarly the steerage should be able to prompt the motherboard with requests such as position() which the motherboard should then process and provide data to steerage.

Further, the motherboard may request info from the steerage module such as currentOrders() or currentSpeed() which the steerage module needs to respond with information.

In future there will be other I2C devices communicating with the motherboard such as a distance sensor etc.

Is this behaviour achievable setting the motherboard as Master and the steerage controller as Slave or would the steerage module need to become Master to interrupt the motherboard?

At the same time, the motherboard could also be waiting for interrupts from any other number of I2C devices.

Any scaffold code for the I2C communication would be appreciated.

I have no experience with I2C

Cheers

If the motherboard is master, the slaves can not push data to the motherboard. The motherboard would have to ask the slave if the turn was completed and/or if the board was OK (not stalled, etc.). The steering board is a slave. It can't ask the motherboard for anything. It's a case of "Shut up until you are called on".

Have a look at this - http://www.arduino.cc/en/Tutorial/MasterReader -

PaulS: If the motherboard is master, the slaves can not push data to the motherboard. The motherboard would have to ask the slave if the turn was completed and/or if the board was OK (not stalled, etc.). The steering board is a slave. It can't ask the motherboard for anything. It's a case of "Shut up until you are called on".

You are correct about slaves not being able to initialize communication, but both AVRs can be masters. I2C is a multi-master bus, the 2 AVR chips can talk back and forth, the Wire library allows for this.