DMA:I2C

The tutorial demonstrates I2C communication through DMA to control OLED display.

Hardware connection

image-20240825210545798

PeripheralsDevelopment boardDescription
OLED: VCC5VOLED power supply
OLED: GNDGNDOLED common ground
OLED: SCLPB8Serial clock line (SCL)
OLED: SDAPB9Serial data line (SDA)

Control principle

STM32F103RCT6 has two DMA controllers, DMA1 has 7 channels and DMA2 has 5 channels;

It is used for high-speed data transmission between peripherals and memory and between memory and memory.

DMA characteristics

DMA initialization and startup are completed by the CPU, and the transmission process is performed by the DMA controller without CPU participation, thus saving CPU resources for other operations.

DMA1 request for each channel

image-20240903165337168

DMA2 request for each channel

image-20240903165345514

This tutorial uses DMA1 channel 6.

Software configuration

Pin definition

Main control chipPinMain function (after reset)Default multiplexing functionRedefine function
STM32F103RCT6PB8PB8TIM4_CH3I2C1_SCL/CAN_RX
STM32F103RCT6PB9PB9TIM4_CH4I2C1_SDA/CAN_TX

Software code

Since the default function of the pin is the ordinary IO pin function, we need to use the redefine function.

Control function

The tutorial only briefly introduces the code, and you can open the project source code to read it in detail.

OLED_I2C_Init

MY_DMA_Transmit_InitConfig

OLED_DMA_Transfer

Experimental phenomenon

The [I2C+DMA.hex] file generated by the project compilation is located in the OBJ folder of the [I2C+DMA] project. Find the [I2C+DMA.hex] file corresponding to the project and use the FlyMcu software to download the program to the development board.

After the program is successfully downloaded: OLED will display oled init success! and I2C + DMA Class! content.