Jane Medium : This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book Medium UART Part of the software use cases .
key word
:MicroPython,MM32F3277
stay MM32F3277 in Eight serial ports , The corresponding serial port is :
UART port (RX,TX):
UART1:PA10, PA9
UART2:PA3,PA2
UART3:PB11,PB10
UART4:PC11,PC10
UART5:PD2,PC12
UART6:PC7,.PC6
UART7:PE7,PE8
UART8:PD1,PD0
Because the first serial port (UART0) Used for interactive interface (REPL), The serial port shown for developers is from UART2 After the serial port .
The following code initializes UART2, The baud rate is 115200, every other 10ms send out 0x55( Corresponding characters ‘U’) data . The serial port sends data through write() Function call to implement , Send one byte at a time .
from machine import Pin,UART
import utime
uart2 = UART(1, 115200)
print('Test UART.')
while True:
_ = uart2.write(b'U')
utime.sleep_ms(10)
Use oscilloscope to test PA2(TX2) The output waveform of :
▲ chart 1.1.1 PA2(TX2) Measure the output waveform
Use a short circuiting device to RXD3 And RXD1 come together , Also is to REPL Receive port of RXD1 Connected to the UART3 Receive port of .
The following program shows how to judge whether a character is received in the serial port , And read the character and store it in the memory buffer . When a carriage return character is received (0xd) after , The received string is converted into an integer and displayed .
from machine import Pin,UART
import utime
uart2 = UART(2, 115200)
print('Test UART.')
buf = bytes(0)
while True:
if uart2.any():
buf = buf + uart2.read(uart2.any())
if buf[-1] == 13:
print(int(buf))
buf = bytes(0)
utime.sleep_ms(10)
The running results are as follows . stay Thonny Enter the number on the interactive interface and press enter , Program variable output corresponding number . If the input character contains non numeric characters , Finally, the program returns with an error .
>> Reset MicroPython...
>> Wait for MicroPython coming back...
>> Download MicroPython : 33 lines/707 characters.
>> -------------------------------------------------------------------------
Test UART.
333
3333
123
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
ValueError: invalid syntax for integer
>>>
This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book Medium UART Part of the software use cases .
■ Links to related literature :
● Related chart Links :