Hi all,
How would I go about using UART 3 on the AF pins D8 & D9...?
--Nick
UART on alternate pins
Re: UART on alternate pins
Edit the pin assignment in mpconfigboard.h for your port and rebuild MicroPython
Re: UART on alternate pins
Perfect, thanks!
Re: UART on alternate pins
I haven't tested this, but I would imagine that you could also manually switch the pins into the UART AF mode?
Code: Select all
u = machine.UART(3)
machine.Pin.board.Y9.init(mode=machine.Pin.IN) # Reset default TX to hi-z
machine.Pin.board.Y10.init(mode=machine.Pin.IN) # Reset default RX to hi-z
machine.Pin.cpu.D8.init(mode=machine.Pin.ALT, alt=AF7_USART3) # TX af
machine.Pin.cpu.D9.init(mode=machine.Pin.ALT, alt=AF7_USART3) # RX af
Re: UART on alternate pins
Nice suggestion Jimmo, and I got a chance to have a play with this approach today.
In short, yes this works fine, you just have to make sure you clear the original pins of their alternate function after the uart is initialized. Your code snippet only created the uart and I was then initializing it to test after the pin reassignments. To future readers (or more likely, future me:) this doesn't work as the init() resets the function of the original pins and while TX will likely work, RX will not work.
Appreciate your suggestion, I got it working after the original posting by editing/building the firmware, but clearly this is easier!
For reference, working code on PYBD F6-
In short, yes this works fine, you just have to make sure you clear the original pins of their alternate function after the uart is initialized. Your code snippet only created the uart and I was then initializing it to test after the pin reassignments. To future readers (or more likely, future me:) this doesn't work as the init() resets the function of the original pins and while TX will likely work, RX will not work.
Appreciate your suggestion, I got it working after the original posting by editing/building the firmware, but clearly this is easier!
For reference, working code on PYBD F6-
Code: Select all
from pyb import Pin, UART
u = UART(3,19200)
Pin.board.Y9.init(mode=Pin.IN) # Reset default TX to hi-z
Pin.board.Y10.init(mode=Pin.IN) # Reset default RX to hi-z
Pin.cpu.D8.init(mode=Pin.ALT, pull=Pin.PULL_UP, alt=Pin.AF7_USART3) # TX (settings copied from init() of default pins)
Pin.cpu.D9.init(mode=Pin.ALT, pull=Pin.PULL_UP, alt=Pin.AF7_USART3) # RX