problem using I2C (scl='B10', sda='B11') with STM32WB55 port

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
etessier
Posts: 4
Joined: Mon Oct 12, 2020 8:04 am

problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by etessier » Mon Oct 12, 2020 10:04 am

Hello everybody,

It's my first post on this forum.

I encounter some difficulties to use I2C bus using B10 and B11 pins on a NUCLEO-WB55 board and a custom STM32WB55 board.
I'm using MicroPython version v1.13-94-g817b89a10-dirty (NUCLEO-WB55 port).

Using NUCLEO-WB55 board and an I2C MPU device (BMP280), I can observe different behaviors according to pins used:
  1. SCL on 'B8' and SDA on 'B9' (corresponding to I2C1 in NUCLEO_WB55/mpconfigboard.h)

    Code: Select all

    import machine
    i2c = machine.I2C(1) # I2C1
    i2c.scan() # => OK, return [118]
    i2c = machine.SoftI2C(scl=machine.Pin('B8'), sda=machine.Pin('B9'))
    i2c.scan() # => OK, return [118]
    
  2. SCL on 'C0' and SDA on 'C1' (corresponding to I2C3 in NUCLEO_WB55/mpconfigboard.h)

    Code: Select all

    import machine
    i2c = machine.I2C(3)
    i2c.scan() # => OK, return [118]
    i2c = machine.SoftI2C(scl=machine.Pin('C0'), sda=machine.Pin('C1'))
    i2c.scan() # => OK, return [118]
    
  3. SCL on 'B10' and SDA on 'B11'

    Code: Select all

    import machine
    i2c = machine.SoftI2C(scl=machine.Pin('B10'), sda=machine.Pin('B11'))
    i2c.scan() # => KO, return []
    
  4. SCL on 'C0' and SDA on 'B11'

    Code: Select all

    import machine
    i2c = machine.SoftI2C(scl=machine.Pin('C0'), sda=machine.Pin('B11'))
    i2c.scan() # => OK, return [118]
    
  5. SCL on 'B10' and SDA on 'C1'

    Code: Select all

    import machine
    i2c = machine.SoftI2C(scl=machine.Pin('B10'), sda=machine.Pin('C1'))
    i2c.scan() # => KO, return []
    
I do not understand why the command i2c.scan() returns an empty list (instead of BMP280 chipid 118) when the device uses SCL 'B10' pin.
Note : In STM32WB55 datasheet document, I2C3_SCL is contained int he list of alternate functions of PB10 pin.

Is someone have an idea ?

Thank in advance for your help.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by jimmo » Tue Oct 20, 2020 6:38 am

etessier wrote:
Mon Oct 12, 2020 10:04 am
In STM32WB55 datasheet document, I2C3_SCL is contained int he list of alternate functions of PB10 pin.
You're using SoftI2C so the alternate function doesn't matter (that only applies to using the hardware I2C peripheral).

Do you have an oscilloscope that you can hook up to B10?

FWIW, you can use the hardware I2C on I2C3 via:

Code: Select all

b10 = machine.Pin.cpu.B10
b11 = machine.Pin.cpu.B11
b10.init(mode=machine.Pin.ALT, alt=machine.Pin.AF4_I2C3)
b11.init(mode=machine.Pin.ALT, alt=machine.Pin.AF4_I2C3)
i2c = machine.I2C(3)

etessier
Posts: 4
Joined: Mon Oct 12, 2020 8:04 am

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by etessier » Thu Oct 22, 2020 4:03 am

Thank you jimmo for your response.
I will test your solution as soon as I have the board (left at my work this week).
Best Regards.
Last edited by etessier on Fri Oct 30, 2020 4:18 pm, edited 1 time in total.

etessier
Posts: 4
Joined: Mon Oct 12, 2020 8:04 am

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by etessier » Wed Oct 28, 2020 1:22 pm

I performed some complementary tests using micropython tagged v1.13 (and not daily version).

I compile STM32 port with BOARD=NUCLEO_WB55 with mpconfigboard.h including the I2C3 configuration :

Code: Select all

#define MICROPY_HW_I2C3_SCL         (pin_C0)    // Arduino A0, pin 28 on CN7
#define MICROPY_HW_I2C3_SDA         (pin_C1)    // Arduino A1, pin 30 on CN7
The following code is working properly

Code: Select all

import machine
i2c=machine.I2C(3)
i2c.scan() # => return [118] corresponding to I2C address of BMP280 device
When modifying I2C3 configuration to :

Code: Select all

#define MICROPY_HW_I2C3_SCL         (pin_B10)
#define MICROPY_HW_I2C3_SDA         (pin_B11)
the scan returns an empty list.
The result is identical if I use the proposed code:

Code: Select all

import machine
b10 = machine.Pin.cpu.B10
b11 = machine.Pin.cpu.B11
b10.init(mode=machine.Pin.ALT, alt=machine.Pin.AF4_I2C3)
b11.init(mode=machine.Pin.ALT, alt=machine.Pin.AF4_I2C3)
i2c = machine.I2C(3)
print(b10) # Pin(Pin.cpu.B10, mode=Pin.OPEN_DRAIN)
print(b11) # Pin(Pin.cpu.B11, mode=Pin.OPEN_DRAIN)
i2c.scan() # []
Using a multimeter after that, the pin B10 level is set to high (3.3V).

I now have a doubt about how I have configure I2C3. Is mpconfigboard.h modification is sufficient to make I2C3(SCL=B10,SDA=B11) working ?

Thank you in advance for your help

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by jimmo » Wed Oct 28, 2020 11:54 pm

etessier wrote:
Wed Oct 28, 2020 1:22 pm
I now have a doubt about how I have configure I2C3. Is mpconfigboard.h modification is sufficient to make I2C3(SCL=B10,SDA=B11) working ?
Yes I think so, it should automatically configure the pin AF when doing it this way.

Do you have access to a logic analyser or a scope?

Or are you even able to control B10/B11 from MicroPython at all? i.e. just using machine.Pin can you set it high/low and see that with the multimeter?

etessier
Posts: 4
Joined: Mon Oct 12, 2020 8:04 am

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by etessier » Fri Oct 30, 2020 3:07 pm

Jimmo,

I followed your advice about testing Pin B10 in mode "OPEN_DRAIN" and found that was finally a connection problem.

I used a small low cost logic analyser with Sigrok/PulseView and observed that Pin B10 was always at level zero.
I read again the documentation about NucleoWB55 board and found in schematics that the test pin 17 of connector CN10 was linked to both pins B10 and A4, via solder bridges SB5 and SB6.

CN10-17 --- SB5 ---> PA4
CN10-17 --- SB6 ---> PB10

By default SB5 is closed and SB6 is open. So CN10-17 was only connected to PA4 (and not connected to PB10).
I closed the solder bridge SB6 and now, PB10 is connected to CN10-17.

Then on this board, after configuring I2C3 with SCL=PB10 and SDA=PB11 (in mpconfigboard.h), the scan() function returns [118] as expected (correct address of my BMP280 device).

Thanks a lot Jimmo !
Best regards.
etessier.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: problem using I2C (scl='B10', sda='B11') with STM32WB55 port

Post by jimmo » Mon Nov 02, 2020 11:20 pm

etessier wrote:
Fri Oct 30, 2020 3:07 pm
By default SB5 is closed and SB6 is open. So CN10-17 was only connected to PA4 (and not connected to PB10).
I closed the solder bridge SB6 and now, PB10 is connected to CN10-17.
Ahhh, I didn't read your first post closely enough -- I saw that you were using a custom board, and didn't realise you were using the Nucleo too.

I should have thought to suggest this...sorry!! The USB Dongle has a very similar gotcha with the UART -- there's actually no way to get access to a UART on the USB Dongle without changing a solder bridge.

Great to hear it's working now! (And yay for Sigrok/PulseView, they're awesome).

Post Reply