1
\$\begingroup\$

I have an i2c oled display with an SSD1306 driver. I want to drive this display with my nucleo card. Pin configurations are shown below.

enter image description here

I provided the i2c connection on the display via i2c1 on the development board. I know that the slave address is 0x3C, but I wanted to check if the display is connected. I couldn't get any address output over UART, below is the code I used for scanning.

    /*-[ I2C Bus Scanning ]-*/
HAL_UART_Transmit(&huart2, StartMSG, sizeof(StartMSG), 10000);
for(i=1; i<128; i++)
{
    ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5);
    if (ret != HAL_OK) /* No ACK Received At That Address */
    {
        HAL_UART_Transmit(&huart2, Space, sizeof(Space), 10000);
    }
    else if(ret == HAL_OK)
    {
        sprintf(Buffer, "0x%X", i);
        HAL_UART_Transmit(&huart2, Buffer, sizeof(Buffer), 10000);
    }
}
HAL_UART_Transmit(&huart2, EndMSG, sizeof(EndMSG), 10000); 
/*--[ Scanning Done ]--*/

I tried to drive the display with different sample codes, but I was not successful with the nucleo board. There is no problem with the display because I can drive it with Arduino.

I couldn't find where I went wrong, can you help?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$
HAL_UART_Transmit(&huart1, StartMSG, sizeof(StartMSG), 10000);
for(i=1; i<128; i++)
{
    ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5);
    if (ret != HAL_OK) /* No ACK Received At That Address */
    {
        HAL_UART_Transmit(&huart1, Space, sizeof(Space), 10000);
    }
    else if(ret == HAL_OK)
    {
        sprintf(Buffer, "0x%X", i); HAL_UART_Transmit(&huart1,Buffer, sizeof(Buffer), 10000);
    }
}
HAL_UART_Transmit(&huart1, EndMSG, sizeof(EndMSG), 10000);
\$\endgroup\$
2
  • \$\begingroup\$ In other words: Use another UART for debug output? \$\endgroup\$
    – Jens
    May 24, 2022 at 17:34
  • \$\begingroup\$ What's the use of using another uart? \$\endgroup\$
    – Enes Orhan
    May 25, 2022 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.