Post Go back to editing



When I try to transmit a buffer to an I2C slave through uart a hard fault is generated (BusFault_Handler B BusFault_Handler

ADI_HAL_STATUS_t I2C_Transmit(uint16_t address,uint8_t *pData, uint8_t size)
/* set slave address to ADPD105 default 0x64 without read0/write1 bits */
if (adi_i2c_SetSlaveAddress(i2CDevice, address)) // bottom-end
//DEBUG_MESSAGE("couldn't set slave device address");
tran.pPrologue=pData; /*!< Prologue pointer. */
tran.nPrologueSize=1; /*!< Prologue byte count. */
tran.pData=pData+1; /*!< Data pointer. */
tran.nDataSize=size-1; /*!< Data byte count. */
/* false to write*/
tran.bReadNotWrite=false; /*!< Read/write flag. */
tran.bRepeatStart=false; /*!< Repeat start flag. */
adi_i2c_ReadWrite(i2CDevice,&tran,&hwErrors) //bug
return ret;

Executing the code step by step shows that the  hard fault is generated when waiting I2C_BUSY in the adi_i2c.c module

static void submitTransaction(ADI_I2C_HANDLE const hDevice, ADI_I2C_TRANSACTION* const pTransaction) {

/* reset internal return code */
hDevice->result = ADI_I2C_SUCCESS;

/* reset hardware error code */
hDevice->hwErrors = ADI_I2C_HW_ERROR_NONE;

/* wait for HW to be ready */
while (I2C_BUSY) {

Could  you define what is the cause of the hardfault?

  • Hello,

    A hardfault could be caused by something corrupting the ADI_I2C_HANDLE structure or by incomplete initialization of the I2C driver.

    Can you show the in initialization code for the I2C? Be sure to call the adi_i2c_Open() method.



  • #define I2C0_SCL0_PORTP0_MUX ((uint16_t) ((uint16_t) 1<<8))
    #define I2C0_SDA0_PORTP0_MUX ((uint16_t) ((uint16_t) 1<<10))

    /* setup I2C Pins */
    *((volatile uint32_t *)REG_GPIO0_CFG) |= I2C0_SCL0_PORTP0_MUX | I2C0_SDA0_PORTP0_MUX;

    void I2C_Init()
        uint8_t devMem[ADI_I2C_MEMORY_SIZE];
        /* open driver */
        if (adi_i2c_Open(0, &devMem, ADI_I2C_MEMORY_SIZE, &i2CDevice))
            //DEBUG_MESSAGE("Failed adi_i2c_Open.");

        /* check reset flow */
        if (adi_i2c_Reset(i2CDevice))
       /* check set speed API */
       if (adi_i2c_SetBitRate(i2CDevice, 400000)) // top-end
           //DEBUG_MESSAGE("adi_i2c_SetBitRate 400000.");

  • Use adi_i2c_Open(0, devMem, ADI_I2C_MEMORY_SIZE, &i2CDevice) without the address-of operator on the memory vector. The function needs the pointer to the vector, not the pointer to the pointer to the vector.

    Let me know if it works.



Reply Children