TWIM: Behaviour when I2C slave not present

Hi,

I have TWIM communicating successfully with a slave device on the PCB.

We now need to support some PCBs populated with the slave device, and other PCBs where the slave device is not populated.

This requires the firmware to determine at run time if the slave is fitted.

To read a register from the slave I am using nrfx_twim_xfer with NRFX_TWIM_XFER_TXRX, and then waiting until nrfx_twim_is_busy is false.

The sequence is:

Master                 Slave

Start

Address+Wr       

                            Slave Ack     What happens in TWIM if the slave does not acknowledge here?

RegisterAddress

                            Slave Ack

Repeated Start   

Address+Rd

                             SlaveAck         

                             Slave Data

Stop

What is the best way to determine if the slave device is present using SDK 15.2?

I ask, because there does not seem to be error associated with the slave not acknowledging the I2C write.

The only events raised by TWIM are:

typedef enum
{
NRFX_TWIM_EVT_DONE, ///< Transfer completed event.
NRFX_TWIM_EVT_ADDRESS_NACK, ///< Error event: NACK received after sending the address.
NRFX_TWIM_EVT_DATA_NACK ///< Error event: NACK received after sending a data byte.
} nrfx_twim_evt_type_t;

The alternative function nrfx_twim_tx seems to only report an error if the slave NACKs the request (compared to no response at all from the slave):

* @retval NRFX_SUCCESS If the procedure was successful.
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
* @retval NRFX_ERROR_INTERNAL If an error was detected by hardware.
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
* @retval NRFX_ERROR_DRV_TWI_ERR_ANACK If NACK received after sending the address in polling mode.
* @retval NRFX_ERROR_DRV_TWI_ERR_DNACK If NACK received after sending a data byte in polling mode.
*/
nrfx_err_t nrfx_twim_tx

Do I need to implement a timeout or is there a way of getting TWIM to indicate the slave did not respond with anything?

Thanks

Dermot

Related