Communicating with sensors and external components is a very common task performed by microcontrollers. The Inter-Integrated Circuit (I2C) bus is a popular protocol used to communicate with external components. In this lesson, we will go over the basics of I2C and learn how to use the I2C peripheral driver in nRF Connect SDK to interface with an external sensor. Typically, in nRF Connect SDK/Zephyr, a sensor driver is developed as a separate module “device driver”. However, in this lesson, we are focusing on learning the I2C APIs, so we will interact directly with the sensor from the application using these APIs.
This lesson has two exercises, depending on which board you are using:
The exercises both demonstrate how to use the I2C driver, so it is sufficient to complete only one of them.
For exercise 1:
Exercise 1 can also be completed using the X-NUCLEO-IKS01A3; however, it is not recommended for new designs (Deprecated Hardware). If you are interested in completing the exercise with the X-NUCLEO-IKS01A3, please follow the instructions for SDK versions v2.0.0 to v2.6.2.
For exercise 2: