Skip to main content
Graduate
July 24, 2024
Question

I2C Scanner

  • July 24, 2024
  • 3 replies
  • 3590 views

I want an I2C Scanner program for STM32F103C8T6 Blue Pill board. i will use external pullup for the i2c clock and data, because the voltage of the devices i am going to scan is 1.8V. The software should find the address of all the devices connected in the bus and return the address to the pc through UART port. default three i2c ports are not true open drain so i need alternate solution.

 

    This topic has been closed for replies.

    3 replies

    Super User
    July 24, 2024

    > default three i2c ports are not true open drain so i need alternate solution.

    Why do you think that?

    Pins can certainly be configured in open drain mode, as referenced many times in the RM.

    TDK_0-1721849234685.png

     

    ctanto333Author
    Graduate
    July 25, 2024
    /* USER CODE BEGIN MX_GPIO_Init_2 */
    	/* Configure I2C GPIO pins: PB6 (I2C1_SCL) and PB7 (I2C1_SDA) */
    	GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
    	GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; // Open-drain mode
    	GPIO_InitStruct.Pull = GPIO_NOPULL; // Use pull-up resistors
    	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // High speed
    	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    /* USER CODE END MX_GPIO_Init_2 */

    I modified the pin as open drain, i used logic analyzer to measure the siganal but it is automatically pulled up.

    Super User
    July 25, 2024

    I don't understand why this is an issue. SDA/SCL should be idle high.

    Graduate II
    July 25, 2024

    If you power your cpu with 1.8v, this looks OK, else you may need level shifter to detect 1.8v signals.

    Visitor II
    July 25, 2024

    I think this will be helpful with some adjustments.

    https://github.com/ScarsFun/STM32_I2C_Scanner

    It is designed for the STM32F103C8T6 board and scans I2C devices, outputting the addresses via USB CDC. To use external pull-ups at 1.8V, you will need to ensure proper hardware configuration, but the software provided in this repository should give you a good starting point. If you ever think of making your own version of Blue Pill, you can see this design: https://www.pcbway.com/project/shareproject/Blue_Dev_Board_Giving_the_STM32_Blue_Pill_a_facelift_223b77e5.html