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 |
|
||||
| ----------------------- | ----------- |
|
||||
| 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 |
|
||||
|
|
|
@ -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>
|
||||
|
||||
// Buffer for serial data -> i2c
|
||||
#define UART_BUFFER_SIZE 16 * 1024
|
||||
CircularBuffer<char,UART_BUFFER_SIZE> uartBuffer;
|
||||
CircularBuffer<byte, 16 * 1024> uartBufferOutbound;
|
||||
|
||||
// Buffer for serial data <- i2c
|
||||
CircularBuffer<byte, 1024> 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
|
||||
|
|
Reference in a new issue