Determining if a Slave is Present on the Bus - KBA83391

Version: *A



How do I determine if a slave with a particular address is present on the bus when using the I2CHW master? 



You can use the API 'I2CHW_fSendStart’ to check if a slave with a specific address is on the bus. This API generates an I2C bus start condition, sends the address and the R/W bit, and then returns the ACK result. If the return value is nonzero, a slave acknowledged the address (is present on the bus). If the return value is zero, a slave did not acknowledge the address (is not present on the bus). The following example code snippet checks if there is a slave with address 0x50 on the bus.

if(I2CHW_fSendStart(0x50, I2CHW_WRITE))
    // Slave present in the bus
    // Slave not present in the bus

I2CHW_bRead(0);  // Set I2CHW_SCR register to use high level API’s
I2CHW_SendStop(); //reset I2C bus
I2CHW_EnableInt(); // re-enable I2C interrupts

// Use high level API like bWriteBytes and fReadBytes here


  1. After checking for the slave, remember to call I2CHW_bRead(0) to set the I2CHW_SCR register to use high level API’s and I2CHW_SendStop to reset the I2C bus.
  2. The fSendStart and SendStop APIs disable I2C interrupts. If you are using high level APIs which require the I2C interrupts (like bWriteBytes and fReadBytes) remember to re-enable I2C interrupts by calling I2CHW_EnableInt().