I2c tx/rx blocking
This commit is contained in:
parent
cffedfd6ba
commit
97862f34a6
@ -35,17 +35,18 @@ int main(void)
|
||||
MX_USART2_UART_Init();
|
||||
MX_I2C1_Init();
|
||||
|
||||
printf("\r\nStarting I2C Scanning:\r\n");
|
||||
for(uint8_t i = 1; i < 128; i++) {
|
||||
uint8_t ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5);
|
||||
if (ret != HAL_OK) { /* No ACK Received At That Address */
|
||||
printf(" - ");
|
||||
} else if(ret == HAL_OK) {
|
||||
printf("0x%X", i);
|
||||
uint8_t data[2] = {0};
|
||||
data[0] = 1; // Config register
|
||||
if(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)(0x48 << 1), data,1, 1000) != HAL_OK) {
|
||||
printf("I2c tx failed.\r\n");
|
||||
} else {
|
||||
if(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)(0x48 << 1), data, 2, 1000) != HAL_OK) {
|
||||
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) {};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user