Page 1 of 2

unable to have I2C2 working on a bluepill

Posted: Thu Feb 06, 2020 3:02 pm
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 ?

Re: unable to have I2C2 working on a bluepill

Posted: Thu Feb 06, 2020 5:28 pm
by fpiSTM
Hi,
Some fixes have been made on I2C for this issue.
You should try the master.

Re: unable to have I2C2 working on a bluepill

Posted: Thu Feb 06, 2020 6:02 pm
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 ?

Re: unable to have I2C2 working on a bluepill

Posted: Thu Feb 06, 2020 6:21 pm
by fpiSTM

Re: unable to have I2C2 working on a bluepill

Posted: Fri Feb 07, 2020 7:38 am
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);

Re: unable to have I2C2 working on a bluepill

Posted: Fri Feb 07, 2020 10:02 am
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 :|

Re: unable to have I2C2 working on a bluepill

Posted: Fri Feb 07, 2020 10:08 am
by fpiSTM
Fine.

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

Re: unable to have I2C2 working on a bluepill

Posted: Fri Feb 07, 2020 5:41 pm
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

Re: unable to have I2C2 working on a bluepill

Posted: Sat Feb 08, 2020 10:18 am
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.

Re: unable to have I2C2 working on a bluepill

Posted: Sat Feb 08, 2020 1:17 pm
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