Page 1 of 2
I2C alternate pin setting not working on STM32 core (solved)
Posted: Tue Oct 17, 2023 3:48 pm
by ManX84
Hi all!
I have a "generic" board with an STM32F103C8. (I use the last core version and for this version,
https://github.com/stm32duino/Arduino_Core_STM32 give version 1.9.0)
On datasheet it is said that for I2C1 I can use PB9 as alternate SDA and PB8 as alternate SCL (confirmed with STM32CUBEmx).
So, with help on I2C example I try this very simple code :
Code: Select all
#include <Wire.h>
TwoWire WIRE1(PB9,PB8);
void setup(){
WIRE1.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop(){
WIRE1.beginTransmission(4); // transmit to device #4
WIRE1.write(x); // sends one byte
WIRE1.endTransmission(); // stop transmitting
x++;
delay(200);
}
I check on Pin PB9 and PB8 with my oscilloscope, nothing happend ! (line stay high, I have 4.6k pull up resistor)
I really not understand where is the problem.. this is very basic code and it must work.. any Id ?
Re: I2C alternate pin setting not working on STM32 core
Posted: Tue Oct 17, 2023 4:13 pm
by fpiSTM
Last version is 2.6.0. Check the readme of the stm32 core on GitHub to get the new link.
Re: I2C alternate pin setting not working on STM32 core
Posted: Tue Oct 17, 2023 4:22 pm
by ManX84
Hello fpiSTM
if you look table
https://github.com/stm32duino/Arduino_C ... 2f1-boards
for STM32F103C8 Generic Board, core version =>1.9.0
??
Re: I2C alternate pin setting not working on STM32 core
Posted: Tue Oct 17, 2023 4:28 pm
by ManX84
In fact even standard Wire not working !!
I test all pins listed in PeripheralPins.c for my STM32 variant !!
Re: I2C alternate pin setting not working on STM32 core
Posted: Tue Oct 17, 2023 5:23 pm
by fpiSTM
Link is
https://raw.githubusercontent.com/stm32 ... index.json
It exists since several years. And stay calm, please.
I know wire works as it was tested several times per week. I will help you tomorrow as since 2.0.0 the way to use pins is different thanks the _ ALTx suffix.
Re: I2C alternate pin setting not working on STM32 core
Posted: Tue Oct 17, 2023 5:36 pm
by ManX84
If I look to my Package, I have:
...\packages\STMicroelectronics\hardware\stm32\2.6.0
So correction, I am in the last core version
Posted: Wed Oct 18, 2023 9:05 am
by fpiSTM
Well, I've tested and have correct result:

- BP_WirePB9_8.png (67.45 KiB) Viewed 4350 times
Are you sure you have well wired PU resistors on each I2C Line.
Select the correct board in the menu: Generic F1, then Generic F103C8 or BluePill F103C8
Re: I2C alternate pin setting not working on STM32 core
Posted: Wed Oct 18, 2023 9:17 am
by ManX84
Hello fpiSTM.
I just try to make a really short test (1 byte sending in while loop) with keil uVision and STM32CUBEmx and it work like that, I have the clock on my oscilloscope !
Select the correct board in the menu: Generic F1, then Generic F103C8 : YES, I have generic F103C8 selected!
Could you send me your .hex I will try it ?
If it work this mean that I have a problem with my arduino IDE configuration (I run the last V2)
Very strange !
Re: I2C alternate pin setting not working on STM32 core
Posted: Wed Oct 18, 2023 9:41 am
by ManX84
Here my full code, just to be sure.
Code: Select all
// I2C Test on STM32F108C
// core STM32 2.6.0
// https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
#include <Wire.h>
TwoWire WIRE1(PB9, PB8);
void setup()
{
WIRE1.setClock(400000); //400khz frequency
WIRE1.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
{
WIRE1.beginTransmission(4); // transmit to device #4
WIRE1.write(x); // sends one byte
WIRE1.endTransmission(); // stop transmitting
x++;
delay(100);
}while(1);
}
I know the loop() is already a while, but just to be sure there are no mistake.. add my own while loop.
Could you try this exact code ?
Thanks for your help!
Re: I2C alternate pin setting not working on STM32 core
Posted: Wed Oct 18, 2023 9:56 am
by ManX84
I am now sure the ide use my STM32 package (I had an incorrect line on the Wire.h from the ...\AppData\Local\arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\libraries\Wire\src\ directory, and I have an error in the IDE console when compiling!
Here my board configuration:

- IDE_CONFIG (Petit).jpg (58.76 KiB) Viewed 4342 times
Really don't understand where is the trap..