I have a Teensy 3.6 with Serial1 connected to an FPGA, and Serial3 connected to an RS-232 transceiver which is connected to my computer.
I just want to relay the messages from the FPGA to my computer, but they keep getting corrupted if watching the serial port isn't the *only* thing the Teensy is doing.
Each message from the FPGA follows this format:
A000001_B000001_C000002_D000002E
There are no newlines, E is the delimiting character, and the 6 numbers after each letter are what I'm really after.
This code gives me the following:
Great. However, if I do anything else, the characters start to get corrupted. For example,
This results in corrupted characters, no newlines, and the the output stops printing anything after a couple seconds:
I have tried while loops, for loops and found that any delay or logic during the UART read line operation leads to corrupted characters.
Now, the output of the FPGA may be a little "shaky". What I mean is that a logic analyzer sometimes has a hard time parsing the output of the FPGA. In this screenshot, you'll see part of an FPGA message, but each character, although recognized, has a "framing error".
(disregard the trace on channel 1)
I can't do much about the FPGA, and I can accept that I won't get every message, but I would very much like to write a method that just "tries" to catch a coherent string from it and send it along.
Any tips on how to write a function or state machine that can "focus" the UART and get a coherent string? DMA comes to mind but that seems overcomplicated. I have tried increasing the RX buffer but that didn't seem to fix the problem. So far, this works the best (although it is still useless, it doesn't crash and it gives me some consistently non-garbage characters):
Result:
Help?
I just want to relay the messages from the FPGA to my computer, but they keep getting corrupted if watching the serial port isn't the *only* thing the Teensy is doing.
Each message from the FPGA follows this format:
A000001_B000001_C000002_D000002E
There are no newlines, E is the delimiting character, and the 6 numbers after each letter are what I'm really after.
This code gives me the following:
Code:
#define fpga_serial Serial1
#define serial_to_host Serial3
void setup() {
fpga_serial.begin(9600);
serial_to_host.begin(9600);
}
char character = 0;
void loop() {
if (fpga_serial.available()) {
character = fpga_serial.read();
if(character != 'E'){
serial_to_host.write(character);
}else{
serial_to_host.println();
}
}
}
Great. However, if I do anything else, the characters start to get corrupted. For example,
Code:
#define fpga_serial Serial1
#define serial_to_host Serial3
void setup() {
fpga_serial.begin(9600);
serial_to_host.begin(9600);
serial_to_host.println("init");
}
void loop() {
if (fpga_serial.available()) {
if(fpga_serial.read() == 'E'){
read_fpga_line();
}
}
}
void read_fpga_line(){
char character = 0;
while(character != 'E'){
serial_to_host.write(character);
character = fpga_serial.read();
}
fpga_serial.println();
fpga_serial.clear();
}
I have tried while loops, for loops and found that any delay or logic during the UART read line operation leads to corrupted characters.
Now, the output of the FPGA may be a little "shaky". What I mean is that a logic analyzer sometimes has a hard time parsing the output of the FPGA. In this screenshot, you'll see part of an FPGA message, but each character, although recognized, has a "framing error".
(disregard the trace on channel 1)
I can't do much about the FPGA, and I can accept that I won't get every message, but I would very much like to write a method that just "tries" to catch a coherent string from it and send it along.
Any tips on how to write a function or state machine that can "focus" the UART and get a coherent string? DMA comes to mind but that seems overcomplicated. I have tried increasing the RX buffer but that didn't seem to fix the problem. So far, this works the best (although it is still useless, it doesn't crash and it gives me some consistently non-garbage characters):
Code:
#define fpga_serial Serial1
#define serial_to_host Serial3
uint8_t FPGArxBuffer[100] DMAMEM;
void setup() {
fpga_serial.begin(9600);
serial_to_host.begin(9600);
serial_to_host.println("init");
fpga_serial.addMemoryForRead(FPGArxBuffer, sizeof(FPGArxBuffer));
}
void loop() {
if (fpga_serial.available()) {
if(fpga_serial.read() == 'E'){
read_fpga_line();
}
}
}
void read_fpga_line(){
char character = 0;
for(int i = 0; i < 32; i++){
serial_to_host.write(fpga_serial.read());
}
serial_to_host.println();
fpga_serial.clear();
}
Result:
Help?