From af189005c99a88108488391547ace4ccaf4fdb61 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sun, 20 Sep 2020 04:19:04 -0400 Subject: [PATCH] Add additional serial ports via SERCOM ; the mux_rpi build now has uart0/1, uart5 and a generic ttl pinout in case others are needed --- hardware/mux_rpi/.gitignore | 2 +- hardware/mux_rpi/README.md | 8 ++--- hardware/mux_rpi/build.ps1 | 2 +- hardware/mux_rpi/mux_rpi.ino | 58 +++++++++++++++++++++++------------- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/hardware/mux_rpi/.gitignore b/hardware/mux_rpi/.gitignore index d163863..11bab7a 100644 --- a/hardware/mux_rpi/.gitignore +++ b/hardware/mux_rpi/.gitignore @@ -1 +1 @@ -build/ \ No newline at end of file +./build/ \ No newline at end of file diff --git a/hardware/mux_rpi/README.md b/hardware/mux_rpi/README.md index 012d2a4..f4a339c 100644 --- a/hardware/mux_rpi/README.md +++ b/hardware/mux_rpi/README.md @@ -27,10 +27,10 @@ This build is ```i2c``` focused for additional parts. Please hookup using standa | Raspberry Pi Header Pin | Arduino Pin | | ----------------------- | ----------- | | 6 | Gnd | -| 8 | A1 | -| 10 | A2 | -| 32 | 10 | -| 33 | 11 | +| 8 (TX) | D11 (RX) | +| 10 (RX) | D10 (TX) | +| 32 (TX) | MISO (RX) | +| 33 (RX) | MOSI (TX) | | 1 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER | | 2 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER | | 3 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER | diff --git a/hardware/mux_rpi/build.ps1 b/hardware/mux_rpi/build.ps1 index 58f6be9..b0604ff 100644 --- a/hardware/mux_rpi/build.ps1 +++ b/hardware/mux_rpi/build.ps1 @@ -1 +1 @@ -arduino-cli compile --log-level=warn --fqbn adafruit:samd:adafruit_feather_m0 _controller.ino +arduino-cli compile --log-level=warn --fqbn adafruit:samd:adafruit_feather_m0 mux_rpi.ino diff --git a/hardware/mux_rpi/mux_rpi.ino b/hardware/mux_rpi/mux_rpi.ino index 6325e30..d74841d 100644 --- a/hardware/mux_rpi/mux_rpi.ino +++ b/hardware/mux_rpi/mux_rpi.ino @@ -9,8 +9,10 @@ #include // Buffer for serial data -> i2c -#define UART_BUFFER_SIZE 16 * 1024 -CircularBuffer uartBuffer; +CircularBuffer uartBufferOutbound; + +// Buffer for serial data <- i2c +CircularBuffer uartBufferInbound; // Board LED Pin #define PIN_BOARD_LED 13 @@ -23,17 +25,19 @@ void timerConfigure(int sampleRate); // Additional serial ports for communication <> RPI // https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports?view=all#creating-a-new-serial -// RX -- A2 -- S 4:1 -// TX -- A1 -- S 4:0 -// RX -- 10 -- S 3:2 -// TX -- 11 -- S 3:0 -Uart rpiUART0 (&sercom4, A1, A2, SERCOM_RX_PAD_1, UART_TX_PAD_0); -Uart rpiUART5 (&sercom3, 10, 11, SERCOM_RX_PAD_2, UART_TX_PAD_0); +// D11 (RX) -- GPIO 8 (TX) +// D10 (TX) -- GPIO 10 (RX) +// MISO (RX) -- GPIO 32 (TX) +// MOSI (TX) -- GPIO 33 (RX) -void SERCOM4_Handler() { +Uart rpiUART0 (&sercom1, 10, 11, SERCOM_RX_PAD_0, UART_TX_PAD_2); +Uart rpiUART5 (&sercom4, PIN_SPI_MISO, PIN_SPI_MOSI, SERCOM_RX_PAD_0, UART_TX_PAD_2); + +void SERCOM1_Handler() { rpiUART0.IrqHandler(); } -void SERCOM3_Handler() { + +void SERCOM4_Handler() { rpiUART5.IrqHandler(); } @@ -46,24 +50,38 @@ void setup() { timerConfigure(TIMER_MILLIS); timerStartCounter(); - // Assign SERCOM functionality - pinPeripheral(A1, PIO_SERCOM); - pinPeripheral(A2, PIO_SERCOM); - pinPeripheral(10, PIO_SERCOM); - pinPeripheral(11, PIO_SERCOM); - // Setup serial ports Serial.begin(115200); + Serial1.begin(115200); rpiUART0.begin(115200); rpiUART5.begin(115200); + + // Assign SERCOM functionality + pinPeripheral(10, PIO_SERCOM); + pinPeripheral(11, PIO_SERCOM); } // Main function +int serialIncomingByte; void loop() { - digitalWrite(PIN_BOARD_LED, HIGH); - delay(500); - digitalWrite(PIN_BOARD_LED, LOW); - delay(500); + while (Serial.available()) { + uartBufferOutbound.push(Serial.read()); + Serial1.write(uartBufferOutbound.last()); + rpiUART0.write(uartBufferOutbound.last()); + rpiUART5.write(uartBufferOutbound.last()); + } + while (Serial1.available()) { + uartBufferInbound.push(Serial1.read()); + Serial.write(uartBufferInbound.last()); + } + while (rpiUART0.available()) { + uartBufferInbound.push(rpiUART0.read()); + Serial.write(uartBufferInbound.last()); + } + while (rpiUART5.available()) { + uartBufferInbound.push(rpiUART5.read()); + Serial.write(uartBufferInbound.last()); + } } // Timer handler