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