Skip to content

GPIO I2C Master*

Note

1. Overview*

GPIO-emulated I2C Master example App, demonstrating how to use two GPIO pins to emulate I2C bus timing and communicate with I2C slave devices. Suitable for scenarios where the chip's hardware I2C resources are insufficient or flexible pin definitions are required.

2. Features*

  • GPIO-emulated I2C Master timing (SCL/SDA)
  • Cross-chip portability (via the porting interface under the port/ directory)
  • Bundled master/slave test programs for communication verification using two development boards

3. Directory Structure*

app/i2c_app/
├── i2c_app.c               # Main program (test program)
├── app.mk                    # Build configuration
├── app.name                  # Kconfig option
├── gpio_i2c/
│   ├── gpio_i2c.c            # GPIO-emulated I2C source file
│   ├── gpio_i2c.h            # GPIO-emulated I2C header file
│   └── port/
│       ├── port.c            # Chip-specific interface implementation
│       └── port.h            # Chip-specific interface header file
└── test/
    ├── fornax_8006_dev_iic_master.zip    # Master device test program
    └── lvp_8002_dev_iic_slave.zip        # Slave device test program
File Description
i2c_app.c Test program, verifies I2C master communication
gpio_i2c/ Core GPIO-emulated I2C implementation
gpio_i2c/port/ Chip porting layer, modify this directory when migrating to other chips
test/ Pre-compiled test programs, can be flashed directly for verification

4. Configuration*

This App has no additional Kconfig sub-configurations. Pin definitions are located in gpio_i2c/port/port.h, configured according to the development board:

GX8006_dev_v1.0 (Master device):

Signal Pin
SCL P8
SDA P14

8002_grus_dev_v1.4 (Slave device):

Signal Pin
SCL P04
SDA P03

5. Working Principle*

5.1 Initialization Flow*

  1. Configure SCL and SDA pins to GPIO mode
  2. Initialize the GPIO I2C Master state machine
  3. Start communication tests with the slave device

5.2 Event Handling*

I2C communication logic is handled in app_event_response().

5.3 Main Loop*

Periodic I2C communication tasks are executed in app_task_loop().

6. Usage*

6.1 Hardware Preparation*

  • Master device: GX8006_dev_v1.0 development board
  • Slave device: 8002_grus_dev_v1.4 development board
  • Connect the SCL and SDA pins of both development boards using jumper wires

6.2 Compilation*

Option 1 (Self-compilation):

cp configs/example/app/8006_gpio_iic_app.config .config
make defconfig
make clean; make

Option 2 (Use pre-compiled test programs directly):

Unzip test/fornax_8006_dev_iic_master.zip and flash it.

6.3 Flashing and Running*

cd tools/bootx/
./flash_nor.sh 0 -r 1000000

Flash test/lvp_8002_dev_iic_slave.zip on the slave device.

6.4 Serial Port Monitoring*

Connect serial port 0 of GX8006_dev_v1.0 to a PC, set the baud rate to 921600, and observe the log output.

7. Expected Output*

  • Test passed: No error messages in the log
  • Test failed: error messages appear in the log; check hardware connections and flashing

8. Notes*

  1. GPIO-emulated timing: The I2C rate of GPIO emulation is lower than hardware I2C and is not suitable for high-speed communication scenarios
  2. Porting interface: When migrating to other chips, modify gpio_i2c/port/port.c and port.h to implement pin initialization and timing control interfaces
  3. Pull-up resistors: The I2C bus requires external pull-up resistors to ensure SCL/SDA are at high level when idle
  4. Suspend/resume not implemented: The current SDK does not support suspend functionality; keep app_suspend() and app_resume() as empty implementations

9. Porting Instructions*

The following files need to be modified when migrating to other chips:

File Modification Content
gpio_i2c/port/port.c Implement chip-specific GPIO initialization, read/write, delay, and other interfaces
gpio_i2c/port/port.h Define chip-specific pin macros and function declarations