I2C alternate pin setting not working on STM32 core (solved)

Post here first, or if you can't find a relevant section!
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

I2C alternate pin setting not working on STM32 core (solved)

Post 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 ?
Last edited by ManX84 on Wed Oct 18, 2023 10:34 am, edited 1 time in total.
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2C alternate pin setting not working on STM32 core

Post by fpiSTM »

Last version is 2.6.0. Check the readme of the stm32 core on GitHub to get the new link.
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post 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

??
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post by ManX84 »

In fact even standard Wire not working !!
I test all pins listed in PeripheralPins.c for my STM32 variant !!
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2C alternate pin setting not working on STM32 core

Post 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.
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post 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
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Post by fpiSTM »

Well, I've tested and have correct result:
BP_WirePB9_8.png
BP_WirePB9_8.png (67.45 KiB) Viewed 864 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
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post 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 !
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post 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!
Exposing your opinion is good, exposing your code is better! :mrgreen:
User avatar
ManX84
Posts: 20
Joined: Tue Oct 17, 2023 3:30 pm

Re: I2C alternate pin setting not working on STM32 core

Post 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
IDE_CONFIG (Petit).jpg (58.76 KiB) Viewed 856 times
Really don't understand where is the trap..
Exposing your opinion is good, exposing your code is better! :mrgreen:
Post Reply

Return to “General discussion”