The default F405 I2C pins are PB6, PB7. How can I use PB8, PB9 instead (they I2C1 alt functions)?
The driver gives an error that pin reassignment is not supported. Presumably it's possible with a custom firmware build?
reassign i2c pins
Re: reassign i2c pins
On the 405 the pin assignments are hard-wired, so rather than selecting them when you create the I2C object, you reconfigure the approriate pins instead.
Rather, you'd do something like this: If you have external pull-up resistors, then you can set pull=pyb.Pin.PULL_NONE rather than using PULL_UP.
In writing up my answer for this, I discovered a bug in Micropython. When you configure the pin as I2C, and then try to switch it to IN mode, it seems to stay in ALT_OPEN_DRAIN mode. If I switch it to OUT mode first, then I can change it to IN mode. I'll see if I can figure out the problem so that you can set it directly to IN mode.
Rather, you'd do something like this:
Code: Select all
i2c = pyb.I2C(1,115200)
# SCL is now on B6
# SDA is now on B7
# Switch B6/B7 back to GPIO inputs
b6 = pyb.Pin('B6', mode=pyb.Pin.OUT)
b6 = pyb.Pin('B6', mode=pyb.Pin.IN)
b7 = pyb.Pin('B7', mode=pyb.Pin.OUT)
b7 = pyb.Pin('B7', mode=pyb.Pin.IN)
# Switch B8/B9 to be I2C (ALT1)
sclPin = pyb.Pin('B8', mode=pyb.Pin.ALT_OPEN_DRAIN, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF4_I2C1)
sdaPin = pyb.Pin('B9', mode=pyb.Pin.ALT_OPEN_DRAIN, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF4_I2C1)
In writing up my answer for this, I discovered a bug in Micropython. When you configure the pin as I2C, and then try to switch it to IN mode, it seems to stay in ALT_OPEN_DRAIN mode. If I switch it to OUT mode first, then I can change it to IN mode. I'll see if I can figure out the problem so that you can set it directly to IN mode.
Re: reassign i2c pins
Thanks a lot! Unlike
Code: Select all
#define MICROPY_HW_I2C1_NAME "I2C1"
#define MICROPY_HW_I2C1_SCL (pin_B6) // SCL
#define MICROPY_HW_I2C1_SDA (pin_B7) // SDA
I may need that anyway, though, as I also changed the REPL to UART6
Code: Select all
#define MICROPY_HW_UART_REPL PYB_UART_6
Code: Select all
pyb.repl_uart(uart)
Bernhard Boser