High-Speed I2C Driver for OLED Screen

Write summaries, discuss careers, and win DJI drones, Redmi tablets, Huawei headphones, and JD cards!

High-Speed I2C Driver for OLED Screen

This article is from the Breadboard Community’s “Lingdong Mini-F5333 Development Board” free evaluation activity.

【Purpose of Experience】Light up the OLED screen and learn to use I2C peripherals.

【Experimental Equipment】

  • MIN-F5333 Development Board

  • OLED Display Screen

【Implementation Steps】

1. Copy the original template project and rename it to MM32F5330_OLED.

High-Speed I2C Driver for OLED Screen

2. Open the project and clean unnecessary module drivers:

High-Speed I2C Driver for OLED Screen

3. Create a new OLED folder, copy the OLED driver used in another project to the new project, create an OLED group in the project, and add OLED.c back to the group while including the header file in the project:

High-Speed I2C Driver for OLED Screen High-Speed I2C Driver for OLED Screen 3. After adding, first include main.h in the library and header files. Import hal_i2c.h in oled.c.

4. Add the I2C initialization function:

This modifies the command write and data write.

void I2C_Configure(void){GPIO_InitTypeDef GPIO_InitStruct;I2C_InitTypeDef I2C_InitStruct;RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);I2C_DeInit(I2C2);I2C_StructInit(&I2C_InitStruct);I2C_InitStruct.I2C_Mode = I2C_MODE_MASTER;I2C_InitStruct.I2C_OwnAddress = I2C_OWN_ADDRESS;I2C_InitStruct.I2C_ClockSpeed = 400000;I2C_Init(I2C2, &I2C_InitStruct);I2C_TargetAddressConfig(I2C2, OLED_I2C_ADDRESS);RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_4);GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_4);GPIO_StructInit(&GPIO_InitStruct);GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_OD;GPIO_Init(GPIOC, &GPIO_InitStruct);I2C_Cmd(I2C2, ENABLE);}

5. Modify the commands for writing commands and data:

/**************************************************************     Prototype      : void WriteCmd(uint8_t IIC_Command)     Parameters     : IIC_Command     return                                        : none     Description    : Write command***************************************************************/void WriteCmd(uint8_t IIC_Command){     uint8_t dat;     dat = IIC_Command;     I2C_SendData(I2C2, 0x00);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }                I2C_SendData(I2C2, dat);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }     I2C_GenerateSTOP(I2C2, ENABLE);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }} /**************************************************************     Prototype      : void WriteDat(uint8_t IIC_Data)     Parameters     : IIC_Data     return                                        : none     Description    : Write data***************************************************************/void WriteDat(uint8_t IIC_Data){     uint8_t dat;     dat = IIC_Data;     I2C_SendData(I2C2, 0x40);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }                I2C_SendData(I2C2, dat);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }     I2C_GenerateSTOP(I2C2, ENABLE);     while (RESET == I2C_GetFlagStatus(I2C2, I2C_STATUS_FLAG_TFE))     {     }}

6. Write the test function in main.c, and upload it to the development board to successfully drive the OLED screen.High-Speed I2C Driver for OLED Screen 【Summary】

This time, the simulated I2C I tested could only reach a maximum of 45KHz, but using hardware I2C configured to 400K speed can achieve 350K speed, making the refresh rate for a single screen extremely fast.

High-Speed I2C Driver for OLED Screen

Attached driver code, feel free to take it (or click Read Original at the End):

https://mbb.eet-china.com/forum/topic/138844_1_1.html

This article is from the Breadboard Community’s “Lingdong Mini-F5333 Development Board” free evaluation activity.

END

High-Speed I2C Driver for OLED Screen

Leave a Comment