aboutsummaryrefslogtreecommitdiff
path: root/nicla/serial_test.py
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-06-06 12:00:58 +0200
committerUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-06-06 12:00:58 +0200
commit077069b82a34bd5e0d51509eb751df9b44a5f6d3 (patch)
tree1753f1266c2837282c7a1f7ce8137161c85a1a0a /nicla/serial_test.py
parentf2335307a26a8ab3e18d8990d2640a8de4cbd0e4 (diff)
parent0f764db3c3595e863a4949c67592451c7d65a2cf (diff)
Merge branch 'master' of https://github.com/unavailabledev/avans-dui
Diffstat (limited to 'nicla/serial_test.py')
-rw-r--r--nicla/serial_test.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/nicla/serial_test.py b/nicla/serial_test.py
new file mode 100644
index 0000000..276f6d1
--- /dev/null
+++ b/nicla/serial_test.py
@@ -0,0 +1,46 @@
+from pyb import Pin, delay, udelay
+
+zumo_tx = Pin("PA10", Pin.IN)
+zumo_rx = Pin("PA9", Pin.OUT_PP)
+
+def uart_send(byte):
+ zumo_rx.value(0)
+ udelay(1000)
+ for x in range(8):
+ bit = (byte & (1 << 7)) >> 7
+ byte <<= 1
+ zumo_rx.value(bit)
+ udelay(1000)
+ zumo_rx.value(1)
+
+__uart_buffer = bytearray()
+def uart_flush():
+ global __uart_buffer
+ print("UART FLUSH START")
+ for byte in __uart_buffer:
+ print(f"BYTE 0x{byte:02X}")
+ uart_send(byte) # dit is de oplossing
+ udelay(2000)
+ uart_send(byte)
+ udelay(2000)
+ uart_send(byte)
+ __uart_buffer = bytearray()
+
+def tx_irq_handler(pin):
+ if pin is zumo_tx:
+ uart_flush()
+
+zumo_tx.irq(trigger = Pin.IRQ_RISING, handler = tx_irq_handler)
+
+def uart_buffer(i):
+ global __uart_buffer
+ __uart_buffer.append(i)
+
+if __name__ == "__main__":
+ while True: # test commands
+ uart_buffer(0x29)
+ uart_buffer(0x70)
+ delay(1000)
+ uart_buffer(0xff)
+ uart_buffer(0x20)
+ delay(1000)