Dtynin
Dtynin
DIIDevHeads IoT Integration Server
Created by Sterling on 7/2/2024 in #middleware-and-os
Could you guys help please review my code and suggest any potential mistakes or improvements?
Alright @Sterling this code example can help guide you to refine your code for more detailed debugging:
while (1) {
HAL_StatusTypeDef result = HAL_I2C_IsDeviceReady(&hi2c1, 0x68 << 1, 10, 1000);

if(result == HAL_OK) {
HAL_UART_Transmit(&huart2, (uint8_t*)"device connected\r\n", 18, 10);
} else {
HAL_UART_Transmit(&huart2, (uint8_t*)"no device\r\n", 11, 10);

char buffer[50];
sprintf(buffer, "I2C Error: %d\r\n", result);
HAL_UART_Transmit(&huart2, (uint8_t*)buffer, strlen(buffer), 10);
}
}
while (1) {
HAL_StatusTypeDef result = HAL_I2C_IsDeviceReady(&hi2c1, 0x68 << 1, 10, 1000);

if(result == HAL_OK) {
HAL_UART_Transmit(&huart2, (uint8_t*)"device connected\r\n", 18, 10);
} else {
HAL_UART_Transmit(&huart2, (uint8_t*)"no device\r\n", 11, 10);

char buffer[50];
sprintf(buffer, "I2C Error: %d\r\n", result);
HAL_UART_Transmit(&huart2, (uint8_t*)buffer, strlen(buffer), 10);
}
}
This will print a detailed error message to help diagnose specific I2C issues
10 replies