程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Software use cases in micropython kernel development notebook: UART related experiments

編輯:Python

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

The contents of the manuscript Objective record
Contents
Basic experiments test UART2 Sending signal test UART3 receive data total junction

 

  • The contents of this manuscript belong to MicroPython Kernel Development Notes : Experimental tasks are embedded in the book The content in .

 

§01 book Draft content


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 .

One 、 Basic experiments

1、 test UART2 Sending signal

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

2、 test UART3 receive data

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
>>>

 

※ total junction ※


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 :

  • MicroPython Kernel Development Notes : Experimental tasks are embedded in the book

● Related chart Links :

  • chart 1.1.1 PA2(TX2) Measure the output waveform

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved