Inter-Integrated Circuit (I²C) Usage Scenarios#
The WiSeConnect SDK for SiWx917 provides flexible APIs for Inter-Integrated Circuit (I²C) communication. You can choose between blocking, nonblocking (DMA), or ultra-low-power (ULP) operation modes depending on your application's performance, timing, and power requirements.
Typical Use Case 1: Blocking (Non-DMA)#
Use blocking mode for short, simple data transfers where the CPU can wait for the transaction to finish. This mode is ideal for small data exchanges, sensor configuration, or initialization steps.
Workflow Overview#
In blocking mode, the I²C API pauses program execution until the transfer completes.
Steps#
Initialize and configure the I²C driver instance.
Set the follower address if required.
Configure FIFO thresholds for optimal data flow.
Use blocking send or receive APIs.
Validate received data and handle errors.
Deinitialize the driver after use.
I²C Leader (Controller) Blocking Example: Step-by-Step Guide#
This example demonstrates how to configure and use blocking I²C communication for a leader (controller) device on the SiWx917 using the WiSeConnect SDK.
Step 1. Configuration and Initialization#
Include required headers, define constants, select the I²C instance, and initialize the driver.
#include "sl_si91x_i2c.h"
...Step 2. Data Transfer Process#
Send and receive data sequentially. Enable or disable repeated starts as needed for your communication sequence.
i2c_status = sl_i2c_driver_send_data_blocking(...);
...Step 3. Data Validation#
Compare transmitted and received data buffers to verify communication integrity.
for (data_index = 0; data_index < I2C_BUFFER_SIZE; data_index++) {
  ...
}Step 4. Error Handling#
Check return values after each API call and log any errors.
if (i2c_status != SL_I2C_SUCCESS) {
    DEBUGOUT("I2C operation failed...");
}Step 5. Clean Up#
Deinitialize the driver to release resources.
sl_i2c_driver_deinit(i2c_instance);I²C Follower (Target) Blocking Example#
In follower mode, the SiWx917 device responds to I²C requests initiated by a leader (controller).
The process is similar to leader mode, but includes a few key differences:
The follower configures and registers its own I²C address.
It receives data without explicitly specifying an address (commonly
0x00).After receiving data, the follower can send a response back to the leader if required.
// Set follower address
sl_i2c_status_t i2c_status = sl_i2c_driver_set_follower_address(...);Recommendations:
Use blocking mode for short transfers (typically 16 bytes or less).
For larger data sizes or continuous communication, use nonblocking DMA-based APIs to improve efficiency and reduce CPU load.
Typical Use Case 2: Nonblocking (DMA)#
Use nonblocking I²C communication when your application requires high data throughput or power efficiency.
In this mode, the Universal DMA (UDMA) controller transfers data between memory and the I²C peripheral, allowing the CPU to perform other operations simultaneously.
This approach is ideal for high-performance or power-sensitive applications that demand continuous or large data transfers.
Nonblocking DMA Workflow Overview#
In nonblocking mode, the WiSeConnect SDK configures UDMA channels to handle I²C data transfers asynchronously.
Your application receives callback notifications when transfers complete or when an error occurs, enabling fully event-driven communication.
Key Points#
Configure DMA channels in
sl_i2c_dma_config_t.Register a callback for completion and error handling.
Use nonblocking send and receive APIs for data transfer.
Example: UDMA-Based I²C Transfer#
The following example demonstrates how to configure UDMA channels, set callbacks, and initiate nonblocking I²C communication on the SiWx917 using the WiSeConnect SDK.
#include "sl_si91x_i2c.h"
...Tip: Nonblocking mode is especially effective for applications that handle large datasets or require parallel CPU activity, such as sensor aggregation, memory streaming, or communication with smart peripherals.
I²C Leader (Controller) Nonblocking Example: Step-by-Step Guide#
This example demonstrates how to configure and use DMA-based nonblocking I²C communication for a leader (controller) device on the SiWx917 using the WiSeConnect SDK.
Step 1. Configuration and Initialization#
Set up DMA channels, register callbacks, and initialize the I²C driver.
p_dma_config.dma_tx_channel = SL_ULP_I2C_DMA_TX_CHANNEL;
...Step 2. Data Transfer#
Initiate nonblocking send and receive operations.
The CPU remains free to execute other tasks while DMA transfers data between memory and the I²C peripheral.
i2c_status = sl_i2c_driver_send_data_non_blocking(...);Step 3. Data Validation#
After the callback signals that the transfer is complete, verify data integrity by comparing transmitted and received buffers.
Step 4. Error Handling#
Implement error checks within the callback function to handle DMA transfer failures or I²C NACK conditions.
Step 5. Clean Up#
Deinitialize the driver after completing all data transfers to release resources.
I²C Follower (Target) Nonblocking Example#
In follower mode, the SiWx917 device responds to requests from the leader using nonblocking DMA-based communication.
This approach allows efficient, asynchronous data handling without occupying the CPU during transfers.
The process is similar to leader mode but includes a few key differences:
The follower uses its own I²C address configuration.
Data reception occurs without specifying an address (commonly
0x00).Callback functions handle data completion or error events in a simplified manner.
// Receive data from leader
i2c_status = sl_i2c_driver_receive_data_non_blocking(...);Typical Use Case 3: Ultra-Low-Power (ULP) I²C Operation#
The Ultra-Low-Power (ULP) I²C mode on the SiWx917 enables energy-efficient communication for IoT devices, wearables, and other battery-powered systems.
This mode leverages the SiWx917’s advanced power management architecture to minimize current consumption during I²C transfers.
ULP Workflow Overview#
In ULP mode, the application configures power domains, enables RAM retention, and executes I²C transactions while transitioning between high-power and low-power states.
You can use this mode to measure and optimize power usage, extending battery life in energy-constrained applications.
Implementation Highlights#
Configure power domains and enable RAM retention.
Initialize the I²C peripheral with ULP settings.
Transition between high-power and ultra-low-power states.
Validate data integrity during and after transfers.
Measure and compare power consumption metrics.
Ultra-Low-Power I²C Leader Example: Step-by-Step Guide#
This example shows how to configure power states and perform I²C data transfers in ULP mode on the SiWx917.
Steps#
Power management and initialization: Configure power domains and initialize the I²C driver.
High-power transaction: Perform a standard I²C transfer in an active power state (PS3 or PS4).
Transition to ULP mode: Move the device into a lower power state (PS2).
ULP transaction: Execute I²C transfers while the processor remains in sleep mode.
Power comparison: Measure current consumption during both power states.
Return to high-power mode: Transition back to PS3 or PS4 for normal operation.
Disable unused peripherals: Shut down nonessential modules to save power.
Battery optimization (optional): Tune transfer intervals and retention settings for maximum efficiency.
Report power metrics: Log or display measured power savings.
Clean up: Deinitialize the driver and release resources.
Tip: Use the ULP I²C controller for periodic sensor polling, data logging, or always-on monitoring while keeping the CPU in sleep mode.
Application Areas#
Battery-powered IoT devices
Sensor networks with duty-cycling
Energy-harvesting or solar-powered systems
Long-term, low-maintenance deployments
Related Example Projects
Explore the WiSeConnect SDK I²C peripheral examples to learn more:
sl_si91x_i2c_driver_leadersl_si91x_i2c_driver_followersl_si91x_i2c_driver_leader_using_transfer_apisl_si91x_ulp_i2c_driver_leader
Reference: WiSeConnect SDK I2C Peripheral Examples