I2c tx/rx blocking

This commit is contained in:
Thomas Klaehn 2021-07-05 15:56:14 +02:00
parent cffedfd6ba
commit 97862f34a6

View File

@ -35,17 +35,18 @@ int main(void)
MX_USART2_UART_Init(); MX_USART2_UART_Init();
MX_I2C1_Init(); MX_I2C1_Init();
printf("\r\nStarting I2C Scanning:\r\n"); uint8_t data[2] = {0};
for(uint8_t i = 1; i < 128; i++) { data[0] = 1; // Config register
uint8_t ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5); if(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)(0x48 << 1), data,1, 1000) != HAL_OK) {
if (ret != HAL_OK) { /* No ACK Received At That Address */ printf("I2c tx failed.\r\n");
printf(" - "); } else {
} else if(ret == HAL_OK) { if(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)(0x48 << 1), data, 2, 1000) != HAL_OK) {
printf("0x%X", i); printf("I2c rx failed.\r\n");
} else {
uint16_t config = (uint16_t)(data[0] << 8) | data[1];
printf("ADS1115 config register: 0x%04x\r\n", config);
} }
} }
printf("\r\nDone! \r\n\r\n");
while(1) {}; while(1) {};
} }