machine.UART
The uart module is mainly used to drive the asynchronous serial port on the development board, and uart can be configured freely. There are 3 uarts in k210, and each uart can be freely mapped.
1. Construction#
1.1. Pin mapping#
Before using uart, we need to use fm to map and manage the chip pins. As shown below, set PIN10 as the sending pin of uart2 and PIN11 as the receiving pin of uart2
1.2. Constructor#
Create a new UART object with the specified parameters
1.2.1. Parameters#
uart
UART number, use the specified UART, which can be completed by pressing the tab key inmachine.UART.
baudrate
: UART baud ratebits
: UART data width, support5/6/7/8
(the default serial port used by REPL (UARTHS) only supports 8-bit mode), default8
parity
: Parity bit, supportNone
,machine.UART.PARITY_ODD
,machine.UART.PARITY_EVEN
(the default serial port (UARTHS) used by REPL only supports None), the default isNone
stop
: stop bit, support1
,1.5
,2
, default1
timeout
: Serial port receiving timeout timeread_buf_len
: serial port receive buffer, serial port receives data through interrupt, if the buffer is full, it will automatically stop data receiving
1.2.2. return value#
- UART object
2. Method#
2.1. init#
It is used to initialize uart, which is generally initialized when constructing the object, here is used to reinitialize uart
2.1.1. Parameters#
Same as constructor, but does not require the first UART number
2.1.2. return value#
no
2.2. read#
Used to read the data in the serial buffer
2.2.1. Parameters#
num
: The number of bytes read, generally fill in the buffer size, if the number of data in the buffer is not as large asnum
, then only the remaining data in the buffer will be returned
2.2.2. return value#
bytes
type of data
2.3. readline#
Used to read one line of serial buffer data
num
: the number of rows read
2.3.1. return value#
*bytes
type of data
2.4. write#
Used to send data using serial port
2.4.1. Parameters#
buf
: Need to send to data
2.4.2. return value#
- The amount of data written
2.5. deinit#
Log off the UART hardware and release the occupied resources
2.5.1. Parameters#
no
2.5.2. return value#
no
2.6. repl_uart()#
Get the serial port object used for REPL
2.6.1. return value#
The serial port object used for REPL, the default initialization bit is 115200 8 N 1
3. Routine#
3.1. Routine 1#
Before running mileage, please make sure that PIN15
has been connected to PIN10
, and PIN17
has been connected to PIN9
After running the program, you can see the printed information of baudrate:115200 bits:8 parity:0 stop:0 ---check Successfully
in the terminal
3.2. Routine 2#
AT module serial port
3.3. Routine 3#
Modify the baud rate of the REPL serial port
3.4. Routine 3#
Modify the REPL serial port
Related Issues not found
Please login GitHub to create issue