UART
— 双工串行通信总线¶
使用示例::(python)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # coding=utf-8
# This is a sample Python script.
import utime
from driver import UART
print("-------------------uart test--------------------")
print("-----How to test: connect PIN10 and PIN12-------")
uart = UART();
uart.open("serial2")
utime.sleep_ms(1000)
writeBuf = bytearray([0x41, 0x42, 0x43, 0x44]);
for i in range(10):
uart.write(writeBuf)
utime.sleep_ms(1000)
readBuf = bytearray(4)
recvSize = uart.read(readBuf)
utime.sleep_ms(100)
print(recvSize)
print(readBuf)
uart.close()
|
配置信息::(json)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # coding=utf-8
# This is a sample cjson file.
{
"version": "0.0.1",
"io": {
"serial1":{
"type":"UART",
"port":1,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
},
"serial2":{
"type":"UART",
"port":2,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
}
},
"debugLevel": "DEBUG",
"repl":"disable"
}
|