yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

11. I2C Communication (I2C)

I2C Communication

I2C CommunicationI. Learning ObjectivesII. I2C IntroductionIII. Hardware SetupIV. Environment SetupV. Main FunctionsVI. Experiment Phenomenon

I. Learning Objectives

  1. Learn and understand basic I2C communication knowledge.
  2. Learn to drive 0.91-inch OLED LCD screen.

II. I2C Introduction

The I2C bus is a bidirectional two-wire serial bus that provides communication lines between integrated circuits. Its meaning is a protocol for completing information exchange between integrated circuits or functional units.

The I2C module receives and transmits data, and converts data from serial to parallel, or parallel to serial. Interrupts can be enabled or disabled. The interface connects to the I2C bus through data pin (SDA) and clock pin (SCL). It allows connection to standard (up to 100kHz) or fast (up to 400kHz) I2C buses. (Data line SDA and clock SCL form the serial bus, which can send and receive data).

The I2C bus has three types of signals during data transmission: start signal (START), stop (end) signal (STOP), and acknowledge signal (ACK). Secondly, it is in idle state when no data transmission is occurring.

I2C Basic Parameters

Speed: I2C bus has two transmission modes: standard mode (100 kbit/s) and fast mode (400 kbit/s), with faster extended mode and high-speed mode also available for selection.

Device Address: Each device has a unique 7-bit or 10-bit address, and communication can be selected through address selection.

Bus Status: I2C bus has five states: idle state, start signal, end signal, response signal, and data transmission.

Data Format: I2C bus has two data formats: standard format and fast format. Standard format is 8-bit data byte plus 1-bit ack/nack (acknowledge/not acknowledge) bit, fast format allows two bytes to be transmitted simultaneously.

Since SCL and SDA lines are bidirectional, they may also have level errors due to external reasons (such as capacitance in the line, etc.), which can lead to communication errors. Therefore, in I2C bus, pull-up resistors are usually used to ensure that the signal lines are at high level in idle state.

III. Hardware Setup

The I2C of MSPM0G series supports master-slave mode, has 7-bit address bits that can be set, supports 100kbps, 400kbps, 1Mbps I2C standard transmission rates, and supports SMBUS. Whether as master or slave, both transmission and reception have independent 8-byte FIFOs. MSPM0 I2C has 8-byte FIFO, generates independent interrupts for controller and target modes, and supports DMA.

img

Software I2C refers to implementing the I2C communication protocol by writing code in the program. It uses general-purpose input/output (GPIO) pins to simulate the I2C data line (SDA) and clock line (SCL), and transmits data and generates timing signals by controlling the level changes of the pins through software. Compared with hardware I2C, the advantage of software I2C is that it does not require specific hardware support and can be implemented on any microcontroller that supports GPIO functionality. It utilizes the general IO pins of the microcontroller to implement the I2C communication protocol. For software I2C, at least two pins are needed for data line (SDA) and clock line (SCL), and it must be ensured that these pins can meet the timing requirements of the I2C communication protocol. The following is a general pin description:

  1. Data Line (SDA): Pin used for transmitting data. In software I2C, this pin needs to be set to output mode (for master device to send data) and input mode (for master device to receive data). During communication, data transmission needs to be achieved by controlling the level changes of the data line.

  2. Clock Line (SCL): Pin used for the clock signal that controls data transmission. In software I2C, this pin needs to be set to output mode, and clock pulses are generated by controlling the level changes of the clock line to control the transmission of the data line. It should be noted that when selecting appropriate pins, the following aspects should be considered:

    • Support input/output configuration: Pins need to support being configured as input or output mode in software and be able to be dynamically switched through programs.
    • Hardware limitations and conflicts: Ensure that selected pins are not assigned to other hardware functions or peripherals to avoid conflicts.
    • Electrical characteristics: The electrical characteristics of pins should meet the standard requirements of I2C bus, such as correct levels and driving capability.

It should be noted that software I2C implementation requires more program code and computation. Compared with hardware I2C, software I2C is more sensitive in terms of processor efficiency and timing control. Therefore, when selecting pins, processor performance and programmability also need to be considered.

This experiment uses software I2C to drive OLED module to display data.

  • I2C Bus Timing Diagram

image-20231024180945251

Idle State

SCL high level, SDA high level;

Start Condition

SCL high level, SDA falling edge;

Stop Condition

SCL high level, SDA rising edge;

Data Transmission

SCL low level, SDA rising edge or falling edge;

Acknowledge Signal

After the slave device receives data, it will send a low level to the master device to indicate successful reception;

Data Validity

When the clock line is high level, the data line must remain stable; when the clock line is low level, the data line is allowed to change.

xxxxxxxxxx
SCL:High level → Used for start and end of communication
SCL:Low level → Used for sending and ending of data

Hardware Connection

Here our I2C interface has built-in pull-up resistors, so when we connect sensor peripherals, we do not need to connect external pull-up resistors

image-20251020220006945

image-20251020220048017

MSPM0G35070.91-inch OLED (SSD1306)
PA15SCL
PA30SDA
3V3VCC
GNDGND

IV. Environment Setup

This section's project is based on the LED case for migration and setup. First, we open the graphical configuration through the sysconfig tool to add peripherals

image-20251020220208975

image-20251020220305561

V. Main Functions

Mainly introduces the user-written functional code, for detailed code, you can open the project files we provide and enter the Bsp folder to view the source code.

Function: OLED_Draw_Line

Function Prototypevoid OLED_Draw_Line(char *data, uint8_t line, bool clear, bool refresh)
Function DescriptionWrite a line of characters
Input Parameter 1data: Display data
Input Parameter 2line: Line number
Input Parameter 3clear: Clear
Input Parameter 4refresh: Refresh
Return ValueNone

Function: void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size1, u8 mode)

Function Prototypevoid OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size1, u8 mode)
Function DescriptionDisplay number function Display number at specified position
Input Parameters 1, 2x,y: Starting coordinates
Input Parameter 3num: Data length
Input Parameter 4size1: Font size
Input Parameter 5mode: 0 inverted display 1 normal display
Return ValueNone

Function: void OLED_ShowChar(u8 x, u8 y, u8 chr, u8 size1, u8 mode)

Function Prototypevoid OLED_ShowChar(u8 x, u8 y, u8 chr, u8 size1, u8 mode)
Function DescriptionDisplay character function Display character at specified position
Input Parameters 1, 2x,y: Starting coordinates
Input Parameter 3chr: Character to display
Input Parameter 4size1: Font size
Input Parameter 5mode: 0 inverted display 1 normal display
Return ValueNone

Function: OLED_ShowString(u8 x, u8 y, u8 *chr, u8 size1, u8 mode)

Function PrototypeOLED_ShowString(u8 x, u8 y, u8 *chr, u8 size1, u8 mode)
Function DescriptionString display function
Input Parameters 1, 2x,y: Starting coordinates
Input Parameter 3Starting address of string to display
Input Parameter 4size1: Font size
Input Parameter 5mode: 0 inverted display 1 normal display
Return ValueNone

VI. Experiment Phenomenon

After the program is flashed, the text "Hello,Yahboom!" is displayed on the OLED screen

image-20251021192127858

Breathing LED (PWM)
External Flash (SPI)

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文