This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1310: I2C raises HW exceptions at random moments

Part Number: CC1310

Tool/software:

In my application i have 2 sensors connected to the same I2C bus. WHen i boot my device it initializes the I2C without errors but then when i try to write to one device the I2C just fails, this error is random since just happens sometimes and I don't know why.  

I have 10k pull-ups on both lines and i ensure only one sensor at a time is using I2C with semaphores. My code is below, but i do not think it is the problem.

/*
 * @brief Initializes the I2C driver.
 * @return TRUE: error.
 *         FALSE: success.
 */
bool i2c_init() {

    I2C_init();
    I2C_Params_init(&i2c_params);
    i2c_params.bitRate = I2C_100kHz;
    i2c_params.transferMode = I2C_MODE_BLOCKING;

    i2c = I2C_open(Board_I2C0, &i2c_params);
    if (i2c == NULL)
        return true;
    return false;
}

/*
 * @brief Writes data to register.
 * @param addr Address of the slave device.
 * @param reg Register to write into.
 * @param data Values to write.
 * @param data_len Amount of bytes to write.
 * @return Status (true = success).
 */
bool i2c_write(const uint8_t addr, uint8_t reg, uint8_t *data, const size_t data_len) {
    if (i2c == NULL || data == NULL || data_len == 0) {
        return false;
    }

    uint8_t tx[16];
    tx[0] = reg;

    size_t i = 0;
    for (i = 0; i < data_len; i++)
        tx[i+1] = data[i];

    uint32_t key = HwiP_disable();

    i2c_transaction.slaveAddress = addr;
    i2c_transaction.writeBuf = tx;
    i2c_transaction.writeCount = data_len + 1;
    i2c_transaction.readBuf = NULL;
    i2c_transaction.readCount = 0;

    bool status = I2C_transfer(i2c, &i2c_transaction);

    HwiP_restore(key);

    return status;
}

/*
 * @brief Reads <data_len> bytes from a register.
 * @param addr Address of the slave device.
 * @param reg Register to start reading from.
 * @param data Buffer where the read data will be stored.
 * @param data_len Amount of bytes to read.
 * @return Status (true = success).
 */
bool i2c_read(const uint8_t addr, uint8_t reg, uint8_t *data, const size_t data_len) {
    if (i2c == NULL || data == NULL || data_len == 0) {
        return false;
    }

    uint32_t key = HwiP_disable();

    i2c_transaction.slaveAddress = addr;
    i2c_transaction.writeBuf = ®
    i2c_transaction.writeCount = 1;
    i2c_transaction.readBuf = data;
    i2c_transaction.readCount = data_len;

    bool status = I2C_transfer(i2c, &i2c_transaction);

    HwiP_restore(key);

    return status;
}