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
This commit is contained in:
parent
76524c01b8
commit
af189005c9
2
hardware/mux_rpi/.gitignore
vendored
2
hardware/mux_rpi/.gitignore
vendored
|
@ -1 +1 @@
|
||||||
build/
|
./build/
|
|
@ -27,10 +27,10 @@ This build is ```i2c``` focused for additional parts. Please hookup using standa
|
||||||
| Raspberry Pi Header Pin | Arduino Pin |
|
| Raspberry Pi Header Pin | Arduino Pin |
|
||||||
| ----------------------- | ----------- |
|
| ----------------------- | ----------- |
|
||||||
| 6 | Gnd |
|
| 6 | Gnd |
|
||||||
| 8 | A1 |
|
| 8 (TX) | D11 (RX) |
|
||||||
| 10 | A2 |
|
| 10 (RX) | D10 (TX) |
|
||||||
| 32 | 10 |
|
| 32 (TX) | MISO (RX) |
|
||||||
| 33 | 11 |
|
| 33 (RX) | MOSI (TX) |
|
||||||
| 1 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
|
| 1 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
|
||||||
| 2 | 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 |
|
| 3 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#include <CircularBuffer.h>
|
#include <CircularBuffer.h>
|
||||||
|
|
||||||
// Buffer for serial data -> i2c
|
// Buffer for serial data -> i2c
|
||||||
#define UART_BUFFER_SIZE 16 * 1024
|
CircularBuffer<byte, 16 * 1024> uartBufferOutbound;
|
||||||
CircularBuffer<char,UART_BUFFER_SIZE> uartBuffer;
|
|
||||||
|
// Buffer for serial data <- i2c
|
||||||
|
CircularBuffer<byte, 1024> uartBufferInbound;
|
||||||
|
|
||||||
// Board LED Pin
|
// Board LED Pin
|
||||||
#define PIN_BOARD_LED 13
|
#define PIN_BOARD_LED 13
|
||||||
|
@ -23,17 +25,19 @@ void timerConfigure(int sampleRate);
|
||||||
|
|
||||||
// Additional serial ports for communication <> RPI
|
// 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
|
// 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
|
// D11 (RX) -- GPIO 8 (TX)
|
||||||
// TX -- A1 -- S 4:0
|
// D10 (TX) -- GPIO 10 (RX)
|
||||||
// RX -- 10 -- S 3:2
|
// MISO (RX) -- GPIO 32 (TX)
|
||||||
// TX -- 11 -- S 3:0
|
// MOSI (TX) -- GPIO 33 (RX)
|
||||||
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);
|
|
||||||
|
|
||||||
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();
|
rpiUART0.IrqHandler();
|
||||||
}
|
}
|
||||||
void SERCOM3_Handler() {
|
|
||||||
|
void SERCOM4_Handler() {
|
||||||
rpiUART5.IrqHandler();
|
rpiUART5.IrqHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,24 +50,38 @@ void setup() {
|
||||||
timerConfigure(TIMER_MILLIS);
|
timerConfigure(TIMER_MILLIS);
|
||||||
timerStartCounter();
|
timerStartCounter();
|
||||||
|
|
||||||
// Assign SERCOM functionality
|
|
||||||
pinPeripheral(A1, PIO_SERCOM);
|
|
||||||
pinPeripheral(A2, PIO_SERCOM);
|
|
||||||
pinPeripheral(10, PIO_SERCOM);
|
|
||||||
pinPeripheral(11, PIO_SERCOM);
|
|
||||||
|
|
||||||
// Setup serial ports
|
// Setup serial ports
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
Serial1.begin(115200);
|
||||||
rpiUART0.begin(115200);
|
rpiUART0.begin(115200);
|
||||||
rpiUART5.begin(115200);
|
rpiUART5.begin(115200);
|
||||||
|
|
||||||
|
// Assign SERCOM functionality
|
||||||
|
pinPeripheral(10, PIO_SERCOM);
|
||||||
|
pinPeripheral(11, PIO_SERCOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main function
|
// Main function
|
||||||
|
int serialIncomingByte;
|
||||||
void loop() {
|
void loop() {
|
||||||
digitalWrite(PIN_BOARD_LED, HIGH);
|
while (Serial.available()) {
|
||||||
delay(500);
|
uartBufferOutbound.push(Serial.read());
|
||||||
digitalWrite(PIN_BOARD_LED, LOW);
|
Serial1.write(uartBufferOutbound.last());
|
||||||
delay(500);
|
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
|
// Timer handler
|
||||||
|
|
Reference in a new issue