Dual Board I2C Slave
Materials
AMB82-mini x 2
Example
I2C Introduction
There are two roles in the operation of I2C, one is “master”, the other is “slave”. Only one master is allowed and can be connected to many slaves. Each slave has its unique address, which is used in the communication between master and the slave. I2C uses two pins, one is for data transmission (SDA), the other is for the clock (SCL). Master uses the SCL to inform slave of the upcoming data transmission, and the data is transmitted through SDA. The I2C example was named “Wire” in the Arduino example.
Introduction
In this example, two AMB82-mini boards communicate with each other over
I2C. One board is configured as the I2C slave at address 0x08, and the
other as the I2C master. The slave listens for 127 bytes sent by the
master via an onReceive callback, verifies the received data, then
sends 127 bytes back to the master via an onRequest callback. This
example demonstrates full two-way I2C communication between two Ameba
boards from the slave’s perspective.
This example uses the I2CSlave_dual sketch on the slave board, paired
with the I2CMaster_dual sketch on the master board. Refer to
Dual Board I2C Master for the full hardware setup and wiring.
Procedure
Setting up the Slave Board
Click Sketch -> Upload to compile and upload the example to the slave AMB82-mini.
Setting up the Master Board
Click Sketch -> Upload to compile and upload the example to the master AMB82-mini.
Wiring
Code Reference
Wire.begin(address) to join the I2C bus as a slave with the given address.Wire.onReceive(handler) to register a callback function that is called when the slave receives data from the master.Wire.onRequest(handler) to register a callback function that is called when the master requests data from this slave.Wire.available() and Wire.read() to read bytes received from the master inside the receive callback.Wire.write() to queue data to be sent to the master inside the request callback.Wire.slaveReadLen() to set the expected number of bytes to read from the master.Wire.slaveWrite() to trigger the slave to prepare and send the queued data to the master.

