SiFli Solution is now fully open: a production-ready solution set that accelerates projects from prototype to mass production. Solution Documentation.

SiFli-Wiki SiFli-Wiki SiFli-Wiki
  • User Guide
  • Examples
  • API Documentation
  • About Us
/
  • English
  • 中文

Quick Start

  • Getting Started
  • Product Documentation Summary

Software Development

  • SDK Programming Guide
  • API Documentation
  • Solution Programming Guide
  • FAQ Frequently Asked Questions
    • Development Tool-Related Issues
      • 1 Compilation-Related
      • 2 Jlink
      • 3 KEIL
      • 4 Ozone
      • 5 SiFli
      • 6 Trace32
      • 7 SystemView
      • 8 UART
      • 9 Source Insight-related
    • Chip-Related Issues
      • 1 GPIO-related
      • 2 Timer-Related
      • 3 Interrupt-related
      • 4 Watchdog-Related
      • 5 RTC Related
      • 6 ADC Related
      • 7 I2C-related
      • 8 Low Power-Related
      • 9 PWM
      • 10 System
      • 11 Bluetooth
      • 12 USB-Related
      • 13 UART-Related
      • 14 Dual-core Related
      • 15 I2S-related
      • 13 SPI Related Issues
    • Peripheral Driver Debugging Issues
      • 1 Common LCD Debugging Issues
      • 2 Common Sensor Debugging Issues
      • 3 Common Flash Debugging Issues
      • 4 Common Motor Debugging Issues
    • Software Debugging-Related Issues
      • 1 Log Debugging
      • 2 Online Debugging Method
      • 3 Restoring the Crash Context from a Memory Dump
      • 4 Methods for Saving the Crash Context
  • Application Notes
    • Low-Power Development Guide
    • Application Startup Flow
    • NandFlash_BBM Analysis Guide
    • SF32LB52-DevKit-Core-3p3 Development Board Test Guide
  • Best Practices
    • AI Xiaozhi

Hardware Development

  • SiFli Selection Guide
    • SiFli Chip Model Guide
    • Module Model Guide
  • Chip Hardware Design Guide
    • SF32LB52x Hardware Design Guide
    • SF32LB52X Hardware Design Guide
    • SF32LB56xU Hardware Design Guide
    • SF32LB56xV Hardware Design Guide
    • SF32LB58x Hardware Design Guide
    • SF32 Series UART Automatic Flashing Design
    • SF32LB55x Hardware Design Guide
    • SF32LB52-MOD-1 Module EPD Display Design Guide
  • Development board
    • Development Board Model Guide
    • SF32LB52-DevKit-LCD Development Board User Guide
    • Guide to Making an LCM Adapter Board for SiFli Development Boards
    • Lichuang Huangshan Pi Development Board User Guide
    • SF32LB52-DevKit-Nano Development Board User Guide
    • SF32LB52-DevKit-Core-3p3 Development Board User Guide
    • SF32LB52-OED-6’-EPD Development Board User Guide
    • SF32LB56-DevKit-LCD Development Board User Guide
    • SF32LB58-DevKit-LCD Development Board User Guide
  • Module

Software Tools

  • Software and Hardware Tool Summary
    • Firmware flashing tool Impeller
    • Graphics Conversion Tool
    • Storage debugging tools
      • Flash Chipid and Type Configuration Guide
    • Screen module debugging
      • Screen module introduction
      • Display module framework introduction
      • Directory structure introduction
        • External
        • Built-in
      • Add display module (1) – Add files (copy files)
      • Add display module (2) – Modify the copied driver files
        • Modify the screen driver
        • Modify the screen TP driver
        • Modify the screen backlight driver
      • Add display module (3) – Modify Kconfig/Menuconfig
      • Example operations for adding a display module
        • SF32LB52x-DevKit-LCD example: adding an SPI-LCD (external)
        • Example: adding a QSPI-LCD on 525 (built-in)
        • Example: adding a DPI-LCD on 566 (built-in)
      • FAQ
      • Appendix
        • Display driver callback functions
        • Mapping table between application-layer functions and module driver-layer functions
        • List of adapted display modules
      • LCD frame-rate calculator
    • sftool

Product Introduction

  • About SiFli

On this page

  • 7.1 Correct I2C initialization method
  • 7.2 I2C communication error after I2C4 enters standby sleep and wakes up
  • 7.3 Intermittent I2C errors
  • 7.4 I2C waveform cannot be output when the I2C device address is 0x12
SiFli-Wiki 0 0
Edit this page
  1. SiFli-Wiki /
  2. FAQ Frequently Asked Questions /
  3. Chip-Related Issues /
  4. 7 I2C-related
View as Markdown Open in ChatGPT Open in Claude

7 I2C-related¶

7.1 Correct I2C initialization method¶

I2C must be initialized and used strictly according to the following three-step method. Otherwise, I2C may not recover properly after sleep wake-up:

rt_i2c_bus_device_find /*第一步find I2C设备*/
rt_device_open /*第二步open I2C设备*/
rt_i2c_configure /*第三步配置 I2C设备*/
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;     /* I2C总线设备句柄 */
int sc7a20_i2c_init()
{
/*第一步find I2C设备*/
   i2c_bus = rt_i2c_bus_device_find("i2c4");
    if (i2c_bus)
    {
        LOG_D("Find i2c bus device I2C4\n");
/*第二步open I2C设备*/
rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_FLAG_RDWR);
/* 或者采用rt_i2c_open函数,但是list_device时I2C不会显示open状态 */
	   	//rt_i2c_open(i2c_bus, RT_DEVICE_FLAG_RDWR);
 
		struct rt_i2c_configuration configuration =
        {
            .mode = 0,
            .addr = 0,
            .timeout = 500, //超时时间(ms)
            .max_hz  = 400000, //I2C速率(hz)
        };
/*第三步配置 I2C设备*/
        rt_i2c_configure(i2c_bus, &configuration);
    }
    else
    {
        LOG_E("Can not found i2c bus I2C4, init fail\n");
        return -1;
    }
    return 0;
   }

7.2 I2C communication error after I2C4 enters standby sleep and wakes up¶

Root cause: When operating the I2C device, only rt_i2c_bus_device_find was used for the I2C4 device, and rt_device_open was not called for this device. In our software architecture, after waking up from standby, whether to restore the I2C configuration is determined by checking whether the I2C device is in the open state. Since I2C4 was not opened, the I2C4 configuration was not restored after waking up from standby, causing I2C4 to be unavailable. As shown in the figure below:
alt text


alt text

Solution: After adding the following open i2c4 operation, the issue was resolved.
alt text


alt text

7.3 Intermittent I2C errors¶

  1. The timeout initialized by rt_i2c_configure is set too short. Due to thread switching, the I2C thread may not get executed, which can easily cause a timeout. 150 ms is recommended. If it is set too long, when an ERR occurs on I2C, the system may hang in the I2C thread. In the figure below, 1000 means 1 second:
    alt text

  2. The I2C rate does not match the pull-up resistor. The rising and falling edges of the I2C waveform are too slow. For 400Kbps, a 1.5K-2.2K pull-up resistor is recommended.

  3. I2C fly-wire debugging. When using fly wires to debug I2C devices such as Touch chips, an overly long bus may cause interference glitches in the I2C waveform, resulting in incorrect I2C waveform recognition.

  4. When some I2C devices encounter an Error, SDA may be held low by the I2C peripheral. When SDA is pulled low, the I2C controller detects that the bus is busy, and SDA cannot output waveforms. The log will print ERR. At this time, the peripheral can be reset. Common reset methods:
    A. Toggle the peripheral power supply or reset pin.
    B. Send an I2C bus reset (9 empty clocks) to reset the peripheral I2C bus. (In the SDK, when an I2C ERR occurs, the HAL layer already resets the I2C controller and sends 9 empty clocks.)

7.4 I2C waveform cannot be output when the I2C device address is 0x12¶

After SDA is pulled low, the I2C controller can no longer output waveforms, as shown in the figure below:
alt text

Root cause: The SF32LB55x chip supports i2c slave mode, and the address of this slave mode was configured as 0x12 in the driver, causing the chip to recognize 0x12 and enter i2c slave mode. The driver is as follows:
alt text

Solution 1: This part of the Lcpu code is in ROM, so modifying it directly will not take effect. Delete the Lcpu ROM function HAL_I2C_Init from rom.sym. And modify this address. Solution 2: After I2C4 device initialization is complete, reconfigure this register directly:
alt text

#define _WWORD(reg,value) \
{ \
    volatile uint32_t * p_reg=(uint32_t *) reg; \
    *p_reg=value; \
}
_WWORD(0x4004c014, 0x01);   //i2c slave_addr 0x01


alt text

Previous
6 ADC Related
Next
8 Low Power-Related

2025, SiFli

Made with Sphinx and Shibuya theme.