Based on RT-Thread I2C (Software) Practice | Technical Collection
1. Hardware and Software Introduction
(1) I2C (Software)
I2C is a widely used short-distance serial communication protocol in embedded systems. It supports multi-master and multi-slave device modes, where the master communicates with slaves via clock signal SCL and data line SDA. In RT-Thread operating system, we can quickly configure the software I2C pins through the menu configuration tool menuconfig, and with its built-in driver implementation, it is convenient and efficient to invoke and develop.
(2) FRDM-MCXA153
FRDM-MCXA153 is a compact and expandable development board that allows rapid prototyping based on MCX A14 and A15 MCUs. They provide industry-standard interfaces, making it easy to access MCU I/O, integrated open standard serial interfaces, external flash memory, and onboard MCU-Link debugger. This article mainly focuses on developing with the NXP FRDM — MCXA153 board and RT-Thread, testing the software I2C functionality and SSD1306 OLED display.
Other tools are provided through the MCUXpresso Developer Experience , such as the extension board center for add-on boards and the application code center for software examples.
(3) SSD1306 OLED
SSD1306 is a single-chip CMOS OLED/PLED driver with an organic/polymer light-emitting diode dot-matrix display controller. It features built-in contrast control, display RAM, and oscillator, reducing external components and power consumption. It offers 256 levels of brightness control. Data/commands are transmitted from the general microcontroller via hardware-compatible 6800/8000 series parallel interface, I2C interface, or serial peripheral interface. It is suitable for many compact portable applications, such as mobile phone secondary displays, MP3 players, calculators, and more.
2. Project Creation
Currently, RT-Thread Studio does not support the BSP for NXP’s FRDM-MCXA153 development board. You need to download the latest mainline source code from Gitee and create the project using the scons command. After downloading the mainline source code, open the scons environment in the directory rt-thread\bsp\nxp\mcx\mcxa\frdm-mcxa153, and configure the software I2C driver and SSD1306 OLED display.
(1) Software I2C Configuration
On the onboard mikroBUS socket of the NXP FRDM-MCXA153 development board, select two pins to serve as the SCL/SDA interface for software I2C. Considering the 3.3V/GND requirements, directly choose P1_0 and P1_2. You can see this from the pinout diagram; the pins are marked within the red box in the diagram.
Since it is software I2C, you can directly select “Use GPIO to soft simulate I2C” in the device driver section of menuconfig. In the configuration, set it to the I2C1 bus. Previously, P1_0 and P1_2 were chosen as SCL/SDA; configure them according to the formula ((port * 32) + pin). The specific configuration is shown in the diagram below.
The implementation details of other software I2C are already handled within RT-Thread components, so they will not be elaborated further.
(2) SSD1306 OLED Configuration
In menuconfig, enable SSD1306, set the I2C bus name accordingly, and the I2C address is defaulted to 0x3C, which does not require modification. Also, enable the SSD1306 test demo.
After configuring the above settings, select Save. Then, execute the following two commands separately:
pkgs --update
scons --target=mdk5
Once the Keil project is generated, open the project and compile the program.
Program Size: Code=83324 RO-data=25164 RW-data=784 ZI-data=7876
Finished: 0 information, 2 warning and 0 error messages.
".\build\rtthread.axf" - 0 Error(s), 6 Warning(s).
Build Time Elapsed: 00:00:04
Finally, download the program to the NXP FRDM-MCXA153 development board.
3. Software I2C Testing
After the firmware is downloaded, reset the system. You should see that the software I2C has been successfully configured.
sram heap, begin: 0x0x200019d4, end: 0x0x20005c00
\ | /
- RT - Thread Operating System
/ | \ 5.2.0 build Jul 21 2024 15:49:40
2006 - 2024 Copyright by RT-Thread team
I/I2C: I2C bus [i2c1] registered
D/I2C_S: Software simulation i2c1 init done, SCL pin: 0x20, SDA pin: 0x22
I/I2C: I2C bus [i2c0] registered
using armclang, version: 6180002
MCXA153 HelloWorld
msh >
By listing the devices, you can confirm that I2C1 is up and running.
msh >list device
device type ref count
-------- -------------------- ----------
i2c0 I2C Bus 0
i2c1 I2C Bus 0
pin Pin Device 0
uart0 Character Device 2
msh >
Then, run the `ssd1306_TestAll` demo.
Compared to hardware I2C, the refresh rate of the software I2C is indeed much slower.