Skip to content

Instantly share code, notes, and snippets.

@rosmianto
Created October 12, 2021 12:17
Show Gist options
  • Save rosmianto/d0d4fbe4b2b343342fcb5f00b71b4747 to your computer and use it in GitHub Desktop.
Save rosmianto/d0d4fbe4b2b343342fcb5f00b71b4747 to your computer and use it in GitHub Desktop.
Snippet to scan connected I2C slaves
#if 1
uint8_t status[128] = {};
for (int i = 1; i < 128; i++) {
HAL_StatusTypeDef ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5);
if (ret != HAL_OK) /* No ACK Received At That Address */
{
status[i] = 0;
}
else if(ret == HAL_OK)
{
status[i] = 1;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment