I2C Interface
I2C Platform interface
I2C Overview
I2C (Inter-Integrated Circuit) is a synchronous, multi-master, multi-slave, packet-switched, single-ended, serial communication protocol used for connecting low-speed peripherals in embedded systems. It is widely used in microcontroller-based systems to interface with sensors, EEPROMs, displays, and other devices.
I2C allows multiple devices to communicate over a two-wire bus: one for the clock signal (SCL) and one for data (SDA). The simplicity of I2C makes it an excellent choice for devices that require low to moderate data transfer rates and minimal hardware resources.
Supported Communication Modes
The following modes of I2C communication are supported:
Blocking - Here the read/write register function waits(blocked) till the operation is performed or time out
Non-Blocking - The read/write register function returns immediately and the registered callback is invoked after the completion of operation or time out
I2C Role Operation
The role operation for I2C determines whether a device operates as the Master or Slave in the I2C communication setup. The role defines how the device interacts with the bus, including controlling data transmission, generating the clock signal, and addressing other devices.
Application Interface
The below table captures the functions that are to be called from the application layer.
Function |
Description |
|---|---|
rs_i2c_open |
To open the I2C interface. |
rs_i2c_set_config |
To configure the I2C interface. |
rs_i2c_master_write_reg16 |
To transfer a 16 bit register address followed by given number of bytes |
rs_i2c_master_write_reg8 |
To transfer a 8 bit register address followed by given number of bytes |
rs_i2c_master_read_reg16 |
To read a 16 bit register address followed by receiving given number of bytes |
rs_i2c_master_read_reg8 |
To read a 8 bit register address followed by receiving given number of bytes |
rs_i2c_register_completion_callback |
To registers the given callback function for completion of I2C transfer operation |
rs_i2c_close |
To close the I2C interface. |
Implementation Guide
This section explains how to implement the I2C interface using the RAPIDSEA stack, the steps to be followed are
Configure the preferred method of RX or TX communication(Blocking / Non-Blocking).
Configure the I2C interface(port, role, slave addr width, bitrate).
Then call the open call of the I2C interface.
Register the callback function.
Perform the read and write register register functions as required and handle the error codes.
Close the I2C interface.
Error Code
Every API’s for the I2C returns some success or failure values. Please refer below section,
Documentation from the relevant header as follows:
Warning
doxygenfile: Cannot find file “rs_i2c.h
To be added for Slave functionality.