diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-24 18:03:05 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-24 18:03:05 +0200 |
commit | cef95354c69745f782a95d37f4b0e7bbf02e106a (patch) | |
tree | ff3a2ce26b1785dc88eb272f41e24ee997c6b4ed | |
parent | 4568db72dc3f9694ecae3506fc3de6ffc948b24f (diff) |
uart working
-rw-r--r-- | nicla/serial_test.py | 19 | ||||
-rw-r--r-- | zumo/.gitignore | 1 | ||||
-rw-r--r-- | zumo/pidtest/.gitignore | 1 | ||||
-rw-r--r-- | zumo/pidtest/makefile (renamed from zumo/pidtest.mk) | 4 | ||||
-rw-r--r-- | zumo/pidtest/pidtest.cpp (renamed from zumo/pidtest.cpp) | 2 | ||||
-rw-r--r-- | zumo/protocol.cpp | 18 | ||||
-rw-r--r-- | zumo/protocol.h | 3 | ||||
-rw-r--r-- | zumo/zumo.ino | 3 |
8 files changed, 34 insertions, 17 deletions
diff --git a/nicla/serial_test.py b/nicla/serial_test.py index bef43a2..c8b84e5 100644 --- a/nicla/serial_test.py +++ b/nicla/serial_test.py @@ -1,21 +1,22 @@ -from pyb import Pin, delay +from pyb import Pin, delay, udelay zumo_tx = Pin("PA10", Pin.IN) zumo_rx = Pin("PA9", Pin.OUT_PP) -def uart_send(s): +def uart_send(byte): zumo_rx.value(0) - byte = ord(s) - print("START BIT") - delay(2) + udelay(1000) for x in range(8): bit = (byte & (1 << 7)) >> 7 byte <<= 1 zumo_rx.value(bit) - print(f"BIT[{x}] = {bit}") - delay(2) - print("STOP BIT") + udelay(1000) zumo_rx.value(1) while True: - uart_send("a") + # uart_send("a") + for x in range(8): + n = 1 << x + uart_send(n) + print(f"0x{n:02x}") + delay(1000) diff --git a/zumo/.gitignore b/zumo/.gitignore index e45f7a2..5761abc 100644 --- a/zumo/.gitignore +++ b/zumo/.gitignore @@ -1,2 +1 @@ *.o -pidtest diff --git a/zumo/pidtest/.gitignore b/zumo/pidtest/.gitignore new file mode 100644 index 0000000..41dc46e --- /dev/null +++ b/zumo/pidtest/.gitignore @@ -0,0 +1 @@ +pidtest diff --git a/zumo/pidtest.mk b/zumo/pidtest/makefile index 5ffe1e1..832d60b 100644 --- a/zumo/pidtest.mk +++ b/zumo/pidtest/makefile @@ -5,8 +5,8 @@ CFLAGS = LFLAGS = TARGET = pidtest -SRCS := pidtest.cpp pid.cpp -OBJS := pidtest.o pid.o +SRCS := pidtest.cpp ../pid.cpp +OBJS := pidtest.o ../pid.o all: pidtest diff --git a/zumo/pidtest.cpp b/zumo/pidtest/pidtest.cpp index b9ce50b..4d047fb 100644 --- a/zumo/pidtest.cpp +++ b/zumo/pidtest/pidtest.cpp @@ -1,7 +1,7 @@ #include <cstdio> #include <random> -#include "pid.h" +#include "../pid.h" int main() { float P, I, D; diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp index fea8a00..f11827c 100644 --- a/zumo/protocol.cpp +++ b/zumo/protocol.cpp @@ -1,4 +1,6 @@ #include <Zumo32U4Motors.h> +#include <Arduino.h> +#include <Wire.h> #include "protocol.h" @@ -34,6 +36,20 @@ void apply_state(dui_state_t *state) { // TODO: print sign on OLED screen } +inline bool rx() { return !digitalRead(DUI_PINOUT_NICLA_RX); } + unsigned char uart_read() { - return 0x00; + if (rx() == true) return 0x00; // return immediately if line is idle + + delayMicroseconds(1500); // wait out start bit + + unsigned char byte = 0x00; + for (unsigned int i = 0; i < 8; i++) { + byte = (byte << 1) | rx(); + delayMicroseconds(1000); + } + + delayMicroseconds(1000); // wait out stop bit + + return byte; } diff --git a/zumo/protocol.h b/zumo/protocol.h index 662a5ce..9db7902 100644 --- a/zumo/protocol.h +++ b/zumo/protocol.h @@ -1,5 +1,8 @@ #pragma once +#define DUI_PINOUT_NICLA_TX 13 +#define DUI_PINOUT_NICLA_RX 14 + typedef enum { DUI_CMD_NULL, DUI_CMD_SIGN, diff --git a/zumo/zumo.ino b/zumo/zumo.ino index c65c2f9..e53513b 100644 --- a/zumo/zumo.ino +++ b/zumo/zumo.ino @@ -5,9 +5,6 @@ #include "protocol.h" #include "pid.h" -#define DUI_PINOUT_NICLA_TX 13 -#define DUI_PINOUT_NICLA_RX 14 - dui_state_t g_dui_target_state = { .steer = 1.0f, .speed = 1.0f, |