Created
October 12, 2021 12:17
-
-
Save rosmianto/d0d4fbe4b2b343342fcb5f00b71b4747 to your computer and use it in GitHub Desktop.
Snippet to scan connected I2C slaves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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