i'm trying a simple sketch to receive date on a 1200 bauds serial port using the hardware.h library
The data sent are a continous serie of 3 bytes espaced by 50 ms of silence
My receive process on the ESP32 (TTGO T-Display) is as follow :
Code: Select all
#include <HardwareSerial.h>
#define SERIAL_PRINTHEX(x) if (x < 16) Serial.print("0"); Serial.print (x,HEX)
HardwareSerial MySerial1(1);
#define RX1 15
#define TX1 17
void setup() {
Serial.begin(115200);
Serial.println("ESP32 Serial Test");
MySerial1.begin(1200 ,SERIAL_8N1, RX1, TX1);
}
long m;
int nbr;
byte Buf[100];
int Bufsize;
void loop() {
nbr = MySerial1.available();
if (nbr > 100) nbr = 100;
for (int i=0; i<nbr; i++) {
Buf[i] = MySerial1.read();
Serial.println();
Serial.print(millis());
Serial.print(" ");
Serial.print(millis()-m);
m = millis();
Serial.print(" Receive_on_port_1 ");;
SERIAL_PRINTHEX(Buf[i]);
}
}
213 47 Receive_on_port_1 11
213 0 Receive_on_port_1 12
213 0 Receive_on_port_1 13
266 53 Receive_on_port_1 11
266 0 Receive_on_port_1 12
266 0 Receive_on_port_1 13
313 47 Receive_on_port_1 11
313 0 Receive_on_port_1 12
313 0 Receive_on_port_1 13
366 53 Receive_on_port_1 11
I would like to read the bytes one by one but instead the library seems to wait for the 3 bytes before returning a non zero value in MySerial1.available()
Is there a kind of tempo used by the library to determine that the reception is finished ?
Is there a parameter to modify to change this behaviour ?
or is there an other library which allow to receive the bytes one by one ?
Thanks for your help