cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Scanner

ctanto333
Associate

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.

 

6 REPLIES 6
TDK
Guru

> 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

 

If you feel a post has answered your question, please click "Accept as Solution".
Techn
Senior II

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

/* 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.

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

If you feel a post has answered your question, please click "Accept as Solution".

@ctanto333 wrote:
I modified the pin as open drain

You shouldn't need to do that - it should be automatically handled by CubeMX when you enable I2C

 


@ctanto333 wrote:
I used logic analyzer to measure the signal but it is automatically pulled up.

Yes, having pullups is a fundamental requirement of I2C - the lines must be pulled up!

 


@ctanto333 wrote:

Blue Pill board


The chances of this having a genuine STM32 are vanishingly small ...

liaifat85
Senior II

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