I2C Communication

I2C CommunicationIntroductionwiringDriving OLEDExpanded contentSSD1306UART and IIC

 

Introduction

In this tutorial, we will learn how to use the I2C interface of K230 to communicate

We will use K230's IIC1 to light up a 128*32 OLED screen as an example of IIC usage.

image-20250401162400298

What is IIC (I2C, I²C)?

Like UART, which we learned in the previous section, IIC (I²C) is also a serial communication protocol. At the end of this tutorial, we will briefly understand the difference between these two communication protocols.

wiring

We wire as shown in the figure:

image-20250401162812664

The actual pictures are as follows:

image-20250401162303852

Driving OLED

Copy the following code into CanMV IDE and run

You can see the effect shown in the picture on the OLED screen.

image-20250401164242873

The flowchart of code execution is as follows:

flow

Expanded content

SSD1306

SSD1306 is a monochrome OLED display controller chip, which is widely used in small display modules.

Driving SSD1306 to display Chinese requires additional processing, and the SSD1306 driver library in the K230 firmware does not support it.

UART and IIC

IIC (I²C) is a serial communications bus developed by Philips for connecting low-speed peripherals to microcontrollers.

It only requires two lines: serial data line (SDA) and serial clock line (SCL), and can support multiple master devices and multiple slave devices.

The main differences between IIC and UART:

How to choose to use IIC or UART ?

Scenarios for using UART:

Scenarios for using IIC: