I2C
We just saw the serial communication protocol. It’s a widely used protocol because it’s verysimple and this simplicity makes it easy to implement on top of other protocols like Bluetooth andUSB.
However, it’s simplicity is also a downside. More elaborated data exchanges, like reading a digitalsensor, would require the sensor vendor to come up with another protocol on top of it.
(Un)Luckily for us, there are plenty of other communication protocols in the embedded space. Someof them are widely used in digital sensors.
The F3 board we are using has three motion sensors in it: an accelerometer, a magnetometer andgyroscope. The accelerometer and magnetometer are packaged in a single component and can be accessedvia an I2C bus.
I2C stands for Inter-Integrated Circuit and is a synchronous serial communication protocol. Ituses two lines to exchange data: a data line (SDA) and a clock line (SCL). Because a clock line isused to synchronize the communication, this is a synchronous protocol.
This protocol uses a master slave model where the master is the device that starts anddrives the communication with a slave device. Several devices, both masters and slaves, can beconnected to the same bus at the same time. A master device can communicate with a specific slavedevice by first broadcasting its address to the bus. This address can be 7 bits or 10 bits long.Once a master has started a communication with a slave, no other device can make use of the busuntil the master stops the communication.
The clock line determines how fast data can be exchanged and it usually operates at a frequency of100 KHz (standard mode) or 400 KHz (fast mode).