2.122.15 TWIHSx_BusScan

C

/* x = TWIHS instance number */

/* TWIHS master mode */
bool TWIHSx_BusScan(uint16_t start_addr, uint16_t end_addr, void* pDevicesList, uint8_t* nDevicesFound)

Summary

Scans number of slaves in the bus.

Description

This function scans the I2C bus to detect devices within a specified address range. It attempts communication with each address from start_addr to end_addr and records the addresses of devices that acknowledge the request. Detected device addresses are stored in a user-provided buffer - pDevicesList, and the total number of devices found is updated in a nDevicesFound variable. The function returns false if pDevicesList and/or nDevicesFound is null or an error occurs. On success, it returns true after completing the scan.

Precondition

None

Parameters

ParamDescription
start_addrThe starting address of the target devices to scan.
end_addrThe ending address of the target devices to scan.
pDevicesListA pointer to a user provided buffer where detected device address will be stored.
nDevicesFoundA pointer to a variable where number of detected devices will be updated.

Returns

true - pDevicesList and nDevicesFound are not null, and the scan completes sucessfully.

false - pDevicesList and nDevicesFound is null, or an error occurs during the scan

Example

uint8_t listOfDevicesFound[20] = {0};
uint8_t numDevicesFound = 0;
bool status = TWHIS1_BusScan(0x10, 0x6E, (void*)listOfDevicesFound, &numDevicesFound);
if (status == true)
{
 //numDevicesFound indicates the number of devices found on the bus
 //listOfDevicesFound contains the address of the I2C target devices discovered during the bus scan
}

Remarks

None.