unable to have I2C2 working on a bluepill

Post here all questions related to STM32 core if you can't find a relevant section!
User avatar
Jblb
Posts: 8
Joined: Fri Jan 03, 2020 4:19 pm
Location: Le Mans
Contact:

unable to have I2C2 working on a bluepill

Post by Jblb »

Hi all
i try to use 2 I2C bus on a bluepill and and I can't get the second one working.
here is my code to setup them

Code: Select all

#include <Wire.h>
// second I2C on PB_11 (SDA) PB_10 (SCL)
TwoWire Wire2(PB_11, PB_10);

[....]

void setup() {
  //alternate pin for I2C1 (wire)
  Wire.setSCL(PB_8);
  Wire.setSDA(PB_9);
  Wire2.setSCL(PB_10);
  Wire2.setSDA(PB_11);

[....]

nothing works on Wire2 but if i swap devices on Wire this is working with the same (ajusted) code.
any ideas where to look to get it working ?

User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by fpiSTM »

Hi,
Some fixes have been made on I2C for this issue.
You should try the master.

User avatar
Jblb
Posts: 8
Joined: Fri Jan 03, 2020 4:19 pm
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by Jblb »

fpiSTM wrote:
Thu Feb 06, 2020 5:28 pm
You should try the master.
Ok i see, now new question: how to use the master ?

User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by fpiSTM »


User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by fpiSTM »

@Jblb

Is it ok ?

About your sketch, by default Wire use I2C1 with PB7 (SDA) / PB6 (SCL).
So seems you want to use also I2C1 on PB9/PB8 which is fine using setSCL/SDA.

For the Wire2 as you already instantiate it with the proper pins, you don't need to re-set the pins using:

Code: Select all

  Wire2.setSCL(PB_10);
  Wire2.setSDA(PB_11);

User avatar
Jblb
Posts: 8
Joined: Fri Jan 03, 2020 4:19 pm
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by Jblb »

hi @fpiSTM

yes it's works, i just miss the wiki page about this, title did not tel me it was about this....

about the second instantiate it's come from tests i made to have it working and forgot to remove :|

User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by fpiSTM »

Fine.

Anyway, one time if you need some support, we can meet few hours ;)

User avatar
Jblb
Posts: 8
Joined: Fri Jan 03, 2020 4:19 pm
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by Jblb »

@fpiSTM

if i remove

Code: Select all

Wire2.setSCL(PB_10);
Wire2.setSDA(PB_11);
Wire2 is not working any more....

need to set my my logic analyzer to get a closer look to signal

User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by fpiSTM »

OK, I think I know why.

You use the Pin Name instead of the pin number:

Code: Select all

TwoWire Wire2(PB11, PB10);
Probably, the second constructor could be added to avoid this kind of issue.
Anyway I guess you should have a warning about argument type.

User avatar
Jblb
Posts: 8
Joined: Fri Jan 03, 2020 4:19 pm
Location: Le Mans
Contact:

Re: unable to have I2C2 working on a bluepill

Post by Jblb »

fpiSTM wrote:
Sat Feb 08, 2020 10:18 am
OK, I think I know why.

You use the Pin Name instead of the pin number:

Code: Select all

TwoWire Wire2(PB11, PB10);
fine you gt it, when I change it's works !
I didn't understand very well the naming of pins/pins number there is something in the wiki about this ?
Probably, the second constructor could be added to avoid this kind of issue.
Anyway I guess you should have a warning about argument type.
I set arduino.logLevel to verbose and there is not any warning

Post Reply

Return to “General discussion”