Quickstart

Informative

The shortest path to a working I2C controller: initialize and write some bytes to a device. Binding rules are in I2c — Requirements; signatures in API Reference.

Bring the driver up

I2c_Init(NULL_PTR);          /* driver: UNINIT -> INIT; every channel -> IDLE */

Write to a device (controller mode)

static const uint8 payload[2] = { 0x10u, 0x2Au };   /* e.g. register index + value */

Std_ReturnType r = I2c_StartTxTransaction(
    0u,        /* channelId (configured as a controller) */
    0x50u,     /* 7-bit device address */
    payload,
    2u);       /* number of bytes */

/* keep payload valid until the completion callout fires */

Handle completion

The driver reports the outcome through callouts. Fill in the matching user code blocks in the generated I2c_Callout_Stubs.c (see The Callout Stub File):

/* in I2c_Callout_Stubs.c */
void I2c_Callout_OnTransmission(uint8 channelId, uint16 length)
{
    /* the write finished; `length` bytes were sent */
}

void I2c_Callout_OnError(uint8 channelId, I2c_ErrorType error)
{
    /* error == I2C_ERR_NACK_RECEIVED if the device did not acknowledge */
}

That is a complete controller write: I2c_Interrupt (or I2c_PollFunction) drives the byte transfer and fires the callout. To read, use I2c_StartRxTransaction and handle I2c_Callout_OnReception (see Controller transactions). To act as a target, see Target transactions.