Strange data over UART.
platformio.ini
[platformio]
default_envs = trans
[env]
platform = [email protected]
board = wiscore_rak4631
framework = arduino
upload_speed = 115200
monitor_speed=9600
[env:trans]
build_flags=
-D TRANSMITTER
[env:rec]
build_flags=
-D RECEIVER
[env:both]
build_flags=
-D RECEIVER
-D TRANSMITTER
main.cpp
#include <Arduino.h>
void setup() {
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000) { delay(100); }
else { break; }
}
Serial1.begin(9600);
while (!Serial1)
{
if ((millis() - timeout) < 5000) { delay(100); }
else { break; }
}
}
void loop() {
#if defined(TRANSMITTER)
Serial1.print("Hello Serial comms");
#endif // defined(TRANSMITTER)
#if defined(RECEIVER)
while(Serial1.available() > 0)
{
char c;
Serial1.readBytes(&c, sizeof(c));
Serial.print(c);
}
Serial.println();
#endif // defined(RECEIVER)
vTaskDelay(50);
}
Pretty simple, right?
If both RECEIVER and TRANSMITTER are defined and the board has Tx1 connected directly to Rx1 then the expected data are received and sent to Serial (verified by connecting Serial to a monitor)
If however one board is loaded with RECEIVER and another with TRANSMITTER and the TRANSMITTER’s Tx1 is connected to the RECEIVER’s Rx1, then the data are corrupt
Does anyone have any idea of what the cause is for this?