-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart_examples.py
More file actions
68 lines (53 loc) · 1.52 KB
/
uart_examples.py
File metadata and controls
68 lines (53 loc) · 1.52 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from uart_interface import *
from threading import Thread
def example_receive(sw):
while(1):
data = uart_receive(sw, 0)
print(f"UART0 RECEIVED: {data}")
time.sleep(2.0)
def example_transmit(sw):
data = []
for i in range (0, 0xff):
data.append(i)
while(1):
uart_send(sw, data, 1)
time.sleep(2.0)
def example_tx_rx(sw):
dataSend = []
dataSendLong = []
data0 = []
data1 = []
data2 = []
dataRec = []
x = 0
for i in range (0x0, 1030):
if i < 0x10: dataSend.append(i)
data0.append(0)
data1.append(1)
data2.append(2)
dataSendLong.append(i)
while(1):
if(x % 4 == 0):
uart_send(sw, data0, 1)
elif(x % 4 == 1):
uart_send(sw, data1, 1)
elif(x % 4 == 2):
uart_send(sw, data2, 1)
else:
uart_send(sw, dataSendLong, 1)
time.sleep(0.1)
if(uart_check_received(sw, 0)):
dataRec = uart_receive(sw, 0)
print(f"UART0 RECEIVED: {dataRec}")
x = x + 1
def main():
with SmartWave().connect() as sw:
uart_init(sw, baudrate=115200 , txlen=8, stop_bits_select=STOP_BITS_1, parity_select=PARITY_SELECT_ODD, shift_direction=SHIFT_LSB_FIRST, timeout_microseconds=9990)
### Example TX/RX
example_tx_rx(sw)
### Example receive:
example_receive(sw)
### Example transmit:
example_transmit(sw)
if __name__ == "__main__":
main()