跳转至

I2C/IIC Error Codes

Standard error codes for I2C operations. More...

Defines

Name
I2C_OK
Success return code.
I2C_ERR_TIMEOUT
Operation timed out (-ETIMEDOUT).
I2C_ERR_NACK
Protocol error / NACK received (-EPROTO).
I2C_ERR_BUSY
Bus or peripheral busy (-EBUSY).
I2C_ERR_IO
Generic I/O error (-EIO).
I2C_ERR_INVAL
Invalid argument supplied (-EINVAL).

Detailed Description

Standard error codes for I2C operations.

This module provides a set of standard error codes for I2C/IIC operations in the CFBD driver suite. All error codes follow POSIX errno conventions.

Macros Documentation

define I2C_OK

#define I2C_OK 0

Success return code.

Par: Example

int status = CFBD_I2CTransfer(bus, msg, count, timeout);
if (status == I2C_OK) {
    // Process received data
    process_data(msg[0].buf, msg[0].len);
}

Returned when an I2C operation completes successfully without errors. All subsequent device states are valid and the operation result (if any) is reliable.

define I2C_ERR_TIMEOUT

#define I2C_ERR_TIMEOUT -110 /* -ETIMEDOUT */

Operation timed out (-ETIMEDOUT).

Par: Recovery Strategy

if (status == I2C_ERR_TIMEOUT) {
    // Option 1: Attempt bus recovery
    CFBD_I2CRecoverBus(bus);

    // Option 2: Retry with extended timeout
    delay_ms(50);
    status = CFBD_I2CTransfer(bus, msg, count, 2000);
}

The I2C operation did not complete within the specified timeout period. This typically indicates:

  • Clock line held low by slave (clock stretching exceeded timeout)
  • No acknowledgment within expected time window
  • Bus unresponsive for entire timeout duration

define I2C_ERR_NACK

#define I2C_ERR_NACK -121 /* -EPROTO (nack) */

Protocol error / NACK received (-EPROTO).

Par: Troubleshooting

if (status == I2C_ERR_NACK) {
    // Check if device is ready
    status = CFBD_I2CTransferIsDeviceReady(bus, addr, 5, 100);

    if (status != I2C_OK) {
        // Device not present or not responding
        return -1;  // Abort operation
    }
}

The addressed slave device did not acknowledge the address or data byte. This indicates:

  • Device not present at specified address
  • Device in error state or not responding
  • Address selection error

define I2C_ERR_BUSY

#define I2C_ERR_BUSY -16 /* -EBUSY */

Bus or peripheral busy (-EBUSY).

Par: Recommended Action

if (status == I2C_ERR_BUSY) {
    // Small delay and retry
    delay_ms(1);
    status = CFBD_I2CTransfer(bus, msg, count, timeout);
}

The I2C bus is currently occupied by another master or the peripheral cannot accept new commands. This is typically a transient condition.

define I2C_ERR_IO

#define I2C_ERR_IO -5 /* -EIO */

Generic I/O error (-EIO).

A generic I/O error occurred during the I2C transaction. This may indicate hardware malfunction, disconnected bus, or electrical issues. The specific cause requires platform-specific debugging.

define I2C_ERR_INVAL

#define I2C_ERR_INVAL -22 /* -EINVAL */

Invalid argument supplied (-EINVAL).

Par: Validation Example

if (addr > 0x7F) {
    return I2C_ERR_INVAL;  // 7-bit address out of range
}
if (num_messages <= 0 || !messages) {
    return I2C_ERR_INVAL;  // Invalid message array
}

Invalid parameters were passed to the I2C function. Common causes:

  • NULL handle or message pointer
  • Invalid device address (outside 7-bit range)
  • Zero message count
  • Invalid timeout value

Updated on 2026-02-03 at 13:21:55 +0000