Increase UART Rx buffer
Posted: 22 Aug 2021 20:47
Hi!
I'm reading power meter data from my power meter (RJ12 P1 port). The meter sends data every 10 seconds.
I however think that I lose packets (dropped packets). Data is received at baud rate 115200. I have a feeling that Z-Uno are unable to keep up reading data from the Rx-buffer before it is overwritten..
Every burst of data is approximately 500-1000 bytes. Is there any way to increase the UART Rx buffer?
This is my code.
I'm reading power meter data from my power meter (RJ12 P1 port). The meter sends data every 10 seconds.
I however think that I lose packets (dropped packets). Data is received at baud rate 115200. I have a feeling that Z-Uno are unable to keep up reading data from the Rx-buffer before it is overwritten..
Every burst of data is approximately 500-1000 bytes. Is there any way to increase the UART Rx buffer?
This is my code.
Code: Select all
#define DEBUG 1 // 1=On, 0=Off
char incomingByte = 0; // for incoming serial data
int numberOfByte = 0; // count number of bytes received
char buffer[500];
void setup()
{
#ifdef DEBUG
Serial.begin();
Serial.println("Inside setup");
#endif
Serial1.begin(115200);
}
void loop()
{
//delay(100); //sleep 1s
while (Serial1.available() > 0)
{
// read the incoming byte:
incomingByte = (char)Serial1.read();
buffer[numberOfByte] = incomingByte & 127;
numberOfByte++;
}
if (numberOfByte > 0)
{
Serial.println("");
Serial.print(numberOfByte, DEC);
Serial.println(":RECEIVE:");
for (int i=0; i<numberOfByte; i++)
{
//Serial.print(buffer);
Serial.print(buffer[i]);
}
numberOfByte = 0; //reset
//Serial1.flush();
}
}