Inter-Integrated Circuit (I²C) API Reference#
Introduction#
The SiWx917 (Si91x family) Inter-Integrated Circuit (I²C) API in the WiSeConnect SDK provides the modules, data types (enumerations/typedefs), configuration structures, functions, and macros needed to configure and use I²C. It enables applications to operate in leader or follower roles, select bus speed and addressing, and perform transfers using blocking, interrupt-driven, or DMA-assisted flows.
Public APIs#
This section introduces the public I²C APIs available on SiWx917. It covers the API surface (modules, enums/typedefs, configuration structs, functions, and macros), usage patterns, and short examples for common tasks. With these APIs you can operate in leader (controller) or follower (target) roles, choose bus speed and addressing, and perform transfers using blocking, interrupt-driven, or DMA-assisted flows.
Complete reference:
I²C Public APIs — WiSeConnect (Si91x)
Callback and Notification APIs#
In addition to synchronous (blocking) calls, the I²C driver supports asynchronous event notifications. By registering an application callback (typically during initialization), your code is notified on transfer completion, errors, and other events—no polling required. This improves efficiency and responsiveness, allowing your application to process other events/tasks until it’s notified.
Callback Function Definition#
The following typedef defines the function signature for callbacks that the I2C driver invokes when an event occurs:
typedef void(* sl_i2c_callback_t)(sl_i2c_instance_t i2c_instance, uint32_t status);Parameters:
i2c_instance: Identifies the I2C instance that generated the event.status: Provides a status code that indicates the result of the I2C operation (for example, success or error).
Usage Guidelines#
Register a callback during I²C initialization (or via the driver’s register-callback API). When an event occurs, the driver invokes your callback so the application can respond (for example, signal completion, schedule the next transfer, or retry after an error). Keep the callback short (no blocking); decode the status to choose the next action and defer heavier work to a task/thread.
Example#
void my_i2c_event_handler(sl_i2c_instance_t i2c_instance, uint32_t status) {
    if (status == SL_I2C_STATUS_OK) {
        // Handle successful transfer
    } else {
        // Handle error
    }
}Integration#
To use callbacks, provide a function pointer in the I²C driver’s init configuration. The driver will invoke your callback on completion and error events.
Initialization prototype:
sl_i2c_status_t sl_i2c_driver_init(sl_i2c_instance_t i2c_instance, const sl_i2c_config_t *p_user_config);Steps#
Implement a callback matching
sl_i2c_callback_t.Assign it to the config struct (e.g.,
config.i2c_callback = my_i2c_event_cb;).Call
sl_i2c_driver_init()with your instance and config.
Example#
void my_i2c_event_handler(sl_i2c_instance_t i2c_instance, uint32_t status) {
    if (status == SL_I2C_STATUS_OK) {
        // Handle successful transfer
    } else {
        // Handle error
    }
}
void app_i2c_init(void)
{
  sl_i2c_config_t config = {0};
  // Fill in role (leader/follower), speed (Standard/Fast/Fm+/HS), addressing, pins, thresholds, etc.
  config.i2c_callback = my_i2c_event_cb;                 // attach your callback
  i2c_driver_init(SL_I2C_INSTANCE_0, &config);       // initialize the driver
}