Common mistakes
Informative
Pitfalls when using the I2C driver, and how to avoid them. Each maps to a rule in I2c — Requirements or an error in Errors.
Passing a real pointer to
I2c_Init.configPtrMUST beNULL_PTR— a non-null pointer raisesI2C_DEVERR_PARAM_POINTER(CHI-I2C-MUST-09). The configuration is selected at build time.Staging the wrong direction in a target. In
I2c_Callout_OnAddressyou must callI2c_StartTxTransactionforI2C_DIR_CONTROLLER_READandI2c_StartRxTransactionforI2C_DIR_CONTROLLER_WRITE; the opposite raisesI2C_DEVERR_INVALID_DIRECTION(CHI-I2C-MUST-20).Freeing the buffer too early.
txDataPtr/rxDataPtrmust stay valid untilI2c_Callout_OnTransmission/I2c_Callout_OnReceptionfires (CHI-I2C-MUST-13).Treating NACK as a fatal driver fault. A device that does not acknowledge is reported as
I2C_ERR_NACK_RECEIVEDviaI2c_Callout_OnError— decide whether to retry, STOP, or abort. Bus and arbitration failures are separate runtime errors (Errors).Using a 10-bit or general-call address. Only 7-bit addressing is supported (
device_addressanddeviceAddrin[0, 127]); the general call address0x00is out of scope.Forgetting to service polled events. If a channel is configured for
Pollingyou must callI2c_PollFunctioncyclically, or no transfer progresses and no callout fires.Expecting a repeated START without one. To keep the bus, start the next transaction inside the completion callout; otherwise the driver issues STOP.