UART communication with another MCU

holyandrei

Member
Hello, so I've search on this forum about this problem and also on internet and asked chatgpt. Did not found a possible root cause for this problem.
I have the following:
- Teensy40 using LPUART8(pins 20/tx and 21/rx) to communicate with atsamd11c14a on pins 9 (tx1) and 10 (rx1). There are 2 ESD diodes on each line to ground (BZX384-6V8).
The link is done as follows:
Pin Teensy/20/tx connects to SAMD11C14A/10/Rx1
Pin Teensy/21/rx connects to SAMD11C14A/9/Tx1

Why I ask for help:
- if I connect the atsamd11c14a to a usb-to-serial to the PC and send the command that I need, the atsamd11c14a responds with what I want.
- if I connect teensy40 on the usb-to-serial to the PC and sniff the USB communication with Wireshark/USBPcap I can see the request command sent by teesny40 being the same with what I send when I test the previous point.
- when I connect both and try to send from teensy to atsamd11c14a then I get no reaction. atsamd11c14a is not providing the response I expect and observe when I test with the PC connection.

BaudRate config is 460800 on both.
Circuit is:
2023-10-01 19_45_23-PCB Layout.jpg

Could be that the problem is with atsamd11c14a. I will find a forum there and ask the same. Could be that the baudrate is not the same even if by the looks, they have the same number.
Code on teensy4 is quite simple:

#define PIN_LED 13
#define PIN_POWER_SET 6
void setup() {
/////////////////// PIN INIT ///////////////////
pinMode(PIN_POWER_SET, OUTPUT);
pinMode(PIN_LED, OUTPUT);
//as init enable power pin
digitalWrite(PIN_POWER_SET, HIGH);
digitalWrite(PIN_LED, HIGH);
delay(100);
//baudrate on teensy side, similar with the other MCU
Serial5.begin(460800, SERIAL_8N1);
}

#define PKT_LEN 6
uint16_t counter = 0;
void loop()
{
delay(1000);
//the request that I am also doing on PC and expect a specific response
//datatype is uint8_t since this is the input expected by "write" function in HardwareSerial library
uint8_t formatted[] = {0xFF, 0x7e, 0x00, 0x00, 0x53, 0x54};
Serial5.write(formatted, PKT_LEN);
//Serial is the USB teensy to log and trace the behavior
Serial.print("DataRead_");
Serial.print(counter);
Serial.print(": ");
delay(50);
while (Serial5.available() > 0) {
delay(10);
Serial.print(Serial5.read(), HEX);
Serial.print(" ");
}
Serial.println("");
counter++;
}
 
Last edited:
You are right, the picture is just for presentation purposes. The project is more complex than that. But there is a ground connection present between the two MCUs.
 
Could be that the baudrate is not the same even if by the looks, they have the same number.

Since your gave a complete program, I tried running it here on a Teensy 4.0. Should be easy enough to check the baud rate.

This is the waveform my oscilloscope sees on pin 20.

file.png
 
Just try a lower rate, like 9600 - just to find out if it's a software or electrical problem.
 
@PaulStoffregen so what I need to do is to get an osci and do the same test on atsamd11c14a. That would be a valid point actually.
 
While probably not the main problem, I do see a possible issue in your code. You have 2 lengthy delays, one inside a loop which tries to receive incoming bytes! That's certainly not good.

Code:
  while (Serial5.available() > 0) {
    [COLOR="#FF0000"]delay(10);[/COLOR]
    Serial.print(Serial5.read(), HEX);
    Serial.print(" ");
  }

At 460800 baud, each byte arrives in 21.7us. A 10ms delay is long enough for almost 461 bytes to arrive! The absolute last thing you should be doing during incoming data is delay longer than the expected time for the amount of data you actually process.
 
I did a test with 9600 on both as @Mcu32 pointed and removed the delay from inside the loop and the one right above the loop (delay(50)). Still no activity. :(
 
Maybe something is wrong on the SAMD11C14A side? Can't really help with that...

If you're completely stuck, maybe using another Teensy as a stand-in for the SAMD11C14A could at least help you move forward. If *that* doesn't work, I and others here could probably help if you show the programs running on both sides. A photo of the wiring between them might also help. We could almost certainly help you get Teensy-to-Teensy communication working.

Maybe once you have it known-good between 2 Teensy boards, then it might be easier to go back to SAMD11C14A with the known-good code and begin troubleshooting SAMD11C14A with all the other parts verified working.
 
Hello, so I've search on this forum about this problem and also on internet and asked chatgpt. Did not found a possible root cause for this problem.
I have the following:
- Teensy40 using LPUART8(pins 20/tx and 21/rx) to communicate with atsamd11c14a on pins 9 (tx1) and 10 (rx1). There are 2 ESD diodes on each line to ground (BZX384-6V8).
The link is done as follows:
Pin Teensy/20/tx connects to SAMD11C14A/10/Rx1
Pin Teensy/21/rx connects to SAMD11C14A/9/Tx1

Why I ask for help:
- if I connect the atsamd11c14a to a usb-to-serial to the PC and send the command that I need, the atsamd11c14a responds with what I want.
- if I connect teensy40 on the usb-to-serial to the PC and sniff the USB communication with Wireshark/USBPcap I can see the request command sent by teesny40 being the same with what I send when I test the previous point.
- when I connect both and try to send from teensy to atsamd11c14a then I get no reaction. atsamd11c14a is not providing the response I expect and observe when I test with the PC connection.

BaudRate config is 460800 on both.
Circuit is:
View attachment 32082
I know that it was asked about having common GND between the two boards... And answered as yes.

And I assume the circuit board above is not complete? It shows an unrouted signal wire between GND and one of the diodes. Again assuming that picture is not correct, but thought I would ask to be sure.

If it were me, I would write some simple sketches for both boards.

That maybe sets up the two pins for digital IO and maybe simple blink sketch that output to pin 20 and do a read on pin 21... Could be as simple or as complex as you feel like doing... Like on the Teensy you could do something like:

Code:
void setup() {
  pinMode(20, OUTPUT);
  pinMode(21, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalToggle(20);
  delay(1);
  digitalWrite(LED_BUILTIN, digitalRead(21));
  delay(500);
}

The other board could have simple echo sketch, maybe something like:
Code:
void (setup) {
    pinMode(10, INPUT);
    pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(9, digitalRead(10));
}
And if both are working and connected, hopefully the LED on the teesny is blinking about once a second...
 
Back
Top