Ameba Arduino: [RTL8195AM] [RTL8710AF] I2C – Communicate with Arduino UNO via I2C
Introduction of I2C
- 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. Although Arduino admitted this name seems to be a mistake, yet the name “Wire” often appear in the examples of Arduino.(Detail of the name “Wire”: https://www.arduino.cc/en/Reference/APIStyleGuide, section “Use full, everyday words.”)
- Ameba x 1
- Arduino UNOx 1
When the I2C Slave receives string sent from I2C Master, it prints the received string.
- Setting up Arduino Uno to be I2C Slave
First, select Arduino in the Arduino IDE in “Tools” -> “Board” -> “Arduino/Genuino Uno”:
- Setting up Ameba to be I2C Master
Open another Arduino IDE window, make sure to choose Ameba in the IDE: “Tools” -> “Board” -> “Arduino Ameba”
The Arduino example uses A4 as the I2C SDA and A5 as the I2C SCL, we can use the same pins on Ameba.
In the Serial Monitor, you can see the messages printed from Arduino Uno.
First use Wire.begin()/Wire.begin(address) to join the I2C bus as a master or slave, in the Master case the address is not required.
Next, the Master uses Wire.beginTransmission(address) to begin a transmission to the I2C slave with the given address:
Uses Wire.write() to send data, and finally use Wire.endTransmission() to end a transmission to a Slave and transmits the bytes that were queued: