Info |
---|
This section refers to the following sample application(s): |
The Inter-Integrated Circuit (I2C) bus is a digital communication bus used to attach low-speed electronic components.
The I2C bus is a two-wire bus.Communication is always initiated by a master but can be bidirectional to get data from slaves. The I2C bus uses the following data lines:
SCL
: Clock to synchronize data transmission.SDA
: Data transmitted in sync with the clock.
I2C on
Include Page |
---|
| _def_chip_eterna |
---|
| _def_chip_eterna |
---|
|
The
libraries allow your application to use the I2C in
master mode. The I2C bus is exposed on the following pins on
Include Page |
---|
| _def_board_fraser |
---|
| _def_board_fraser |
---|
|
.
The figure below is a screen capture of a logic analyzer which shows an I2C write transaction. Here the
Include Page |
---|
| _def_chip_eterna |
---|
| _def_chip_eterna |
---|
|
chip sends three bytes of data (
0x80
,
0x81
,
0x82
) to an I2C slave at address
0x05
. The transaction starts with a start byte to indicate the address of the slave to talk to, and the direction (here "write").
The figure below illustrates a "read" transaction. The
Include Page |
---|
| _def_chip_eterna |
---|
| _def_chip_eterna |
---|
|
chip starts by sending a header byte containing the address of the slave to read from (here
0x05
), as well as the "read" bit. The
Include Page |
---|
| _def_chip_eterna |
---|
| _def_chip_eterna |
---|
|
chip (the I2C master) then sends a clock signal which the slave uses to time the bits it sends back over the SDA line to the master. In this case, the slave returns the bytes
0x2A
,
0x2B
,
0x2C
.
The 02-i2c
Sample Application
This sample application creates a single task (called i2cTask
) which, every second, alternates between sending three bytes and reading three bytes from an I2C slave at address 0x05
. The logic analyzer screenshots above were obtained by running this sample application.
The task automatically starts communicating with the I2C slave when the application is started. It prints the bytes sent and received over the I2C connection.
No Format |
---|
i2c app, ver 1.0.0.2
SmartMeshIP stack, ver 1.2.1.6
Sent to I2C slave 05: 0x808182
Received from I2C slave 05: 0x262728
Sent to I2C slave 05: 0x808182
Received from I2C slave 05: 0x292a2b
Sent to I2C slave 05: 0x808182
Received from I2C slave 05: 0x2c2d2e
Sent to I2C slave 05: 0x808182
Received from I2C slave 05: 0x2f3031 |
The application will print an error when no slave with address 0x05
is present on the I2C bus. The I2C_SLAVE_ADDR
defined at the top of the sample application's main file allows you to easily change the address of the I2C slave.
Include Page |
---|
| _inc_refer_to_dox |
---|
| _inc_refer_to_dox |
---|
|