Could you guys help please review my code and suggest any potential mistakes or improvements?

Good day guys, I'm currently working on a project involving the MCP3424 ADC module and an STM32 microcontroller. My intention is to verify whether the MCP3424 is connected to the master STM32 at the defined address 0x68. While the ADC module successfully connects to an Arduino at the same address, I am facing issues with the STM32 connection.

This is my code ;

while (1) { /* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
    if((HAL_I2C_IsDeviceReady(&hi2c1, 0x68 << 1, 100, 1000))==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);
    }
}


With this, I am still unable to establish a connection with the MCP3424 using the STM32.
The error output keeps showing "no device".

Could you guys help please review my code and suggest any potential mistakes or improvements? Also, if there are specific considerations or configurations needed for interfacing the MCP3424 with the STM32, please I would love to know.
Thanks guys 🙏.
@Middleware & OS
Solution
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);
    }
}


This will print a detailed error message to help diagnose specific I2C issues
Was this page helpful?