Hi everyone,
The following programs do a non-stop communicaction between a nano and a teensy 3.2 chips.
The problem is that teensy reads unwanted zeros among expected received data from nano. And my question is how to remove/avoid them? Ther rest works ok -Nano receives always ok-.
I want to say in advance, that this code is tested and works usind two nanos in two differents boards, and I'm doing all tests with the same and only one power supply feeding the circuits. Teensy is using Serial1 rx/rx pins (0 and 1).
Let me explain what program do. Teensy starts sending and nano receiving. Steps:
- Teensy send a Serial1.write(7) and then waits for a incoming data
- Nano receives a 7 and print it in a lcd display
- When nano incoming buffer becomes empty again, send three numbers via Serial.write() -8, 2 and 47- and then waits for a incoming data again
- Teensy receives "some data", show it via serial monitor -don't have lcd display for them, and when its incoming buffer is empty again the program goes to point 1
The problem is in Step 4, teensy reads unwanted zeros. Let me explain to us all differents cases I tested:
- With code as I sent to you, this is what serial monitor shows: Two non-wanted zeros always come before the data we are expecting for
****** 0 0 8 2 47 ****** 0 0 8 2 47 and in bucle
- Based in initial code, If I put a Serial1.flush() after sending data in teensy -not in nano-, same result as point 1
Serial1.write(7);
Serial.flush();
delay(2);
-
Based in initial codes, If I put a Serial.flush() after sending data in nano -not in teensy-, same result as point 1
-
Based in initial codes, If I put a Serial.flush() and Serial1.flush() in nano and teensy after sending data, same result as point 1
-
Based in initial codes, If I change the delay(200); after Serial1.read(); in teensy to delay(10);, still same two zeros received
****** 0 0 8 2 47 ****** 0 0 8 2 47 in bucle
- Based in code changes from point 5, If I add some Sreial.write() i nano part:
Serial.write(8);
Serial.write(2);
Serial.write(47);
Serial.write(0);
Serial.write(255);
Serial.write(6);
Serial.write(0);
Serial.write(98);
Then the result is only one unwanted zero at the begining of each pack:
****** 0 8 2 47 0 255 6 0 98 ****** 0 8 2 47 0 255 6 0 98 ****** in bucle
- Based in code changes in point 6, if I change current delay(10); after Serial1.read() in teensy, for a delay(2);, then serial monitor show that all data received in teensy is a lonely unwanted 0, and only one for each pack:
****** 0 ****** 0 ****** 0 in bucle
- Based in code changes in point 7, if I put a Serial1.flush() and Serial.flush() as did in points 3 and 4, seems that Serial colapses at third pack of data sended from nano:
****** 0 ****** 0 ****** 0 and no more data showed
- Based in point 7, if I change baud rate from 38400 to 115200 in both chips with Serial1. begin(115200); and Serial.begin(115200) -with delay(2) after reading in teensy-, same result as point 7 is showed in serial monitor
****** 0 ****** 0 ****** 0 in bucle
- Based in point 9, if I change delay(2) to delay(10); again after reading in teensy, same result as point 6 but including two initial unwanted zeros as in point 5, instead of only one
So my question again: how to remove these zeros that we don't expect and in addition they don't show up neither with the same amount nor order? I'm sure that if I do more test probably they show up in the middle or at the end of each data submit, not only at the begining
Very thankful to every one.. I'm really stuck on this
SerialCom_NanoPart.ino (2.74 KB)
SerialCom_Teensy32Part.ino (2.17 KB)