Use I2C in real-time capable applications

Important

This is the Azure Sphere (Legacy) documentation. Azure Sphere (Legacy) is retiring on 27 September 2027, and users must migrate to Azure Sphere (Integrated) by this time. Use the Version selector located above the TOC to view the Azure Sphere (Integrated) documentation.

Azure Sphere supports Inter-Integrated Circuit (I2C) in master mode. I2C is a serial bus that connects lower-speed peripherals to microcontrollers. I2C uses a multi-master/multi-subordinate model where a master device controls a set of subordinate devices. I2C is often used with peripherals that only require simple lightweight communication with a microcontroller, such as setting controls, power switches, and sensors.

This topic describes how to use I2C in real-time capable applications (RTApps). For information about using I2C in high-level applications, see Using I2C in high-level applications.

Note

The Azure Sphere OS does not reset peripherals on start-up. Your applications should ensure that peripherals are in a known-good state on start-up or after restart.

MT3620 support for I2C on the real-time cores

The I2C specifications for the MT3620 chip are listed in MT3620 Support Status. The MT3620 development board user guide describes the pin layout and functions for wiring.

When you configure the MT3620 dev board, you can use any ISU block as an I2C master interface. When you use an ISU block as an I2C master interface, you can't use the same block as a SPI or UART interface.

Ten-bit subordinate device addresses are not supported on the MT3620; only 7-bit addresses are supported. The MT3620 supports 100 KHz, 400 KHz, and 1 MHz bus speeds, but not 3.4 Mhz. Zero-byte I2C reads are not supported on the MT3620.

For register base addresses, interrupt numbers, clock rate, sampling frequency, and other details about the MT3620, see the MT3620 Datasheet and the MT3620 M4 User Manual; if questions remain, you can request details from Avnet by emailing Azure.Sphere@avnet.com.

Application manifest settings

To use I2C, an RTApp must list it in the Capabilities section of the application manifest. For example, the following line reserves an I2C master interface on ISU0 on an MT3620 chip:

"Capabilities": {
   "I2cMaster": [ "ISU0" ] }

Azure Sphere application manifest has more details about the application manifest.

The I2C sample applications

The CodethinkLabs repository on GitHub contains a number of sample applications that demonstrate how to use MT3620 supported peripherals in Azure Sphere RTApps. Specifically, the I2C_RTApp_MT3620_BareMetal sample demonstrates how to use an I2C peripheral in a real-time capable application.