I started out trying to capture a serial stream from a device @115200, but ran into troubles. So I created a bare bones example code to test, and i still cannot capture all the data properly. Am I doing something wrong, or what ?
It seems its filling the 64byte buffer faster than it can pull it out. Sadly acquireSerialBuffer() is not available for serial1 ;(
What I am doing here is I have a terminal window opened on the Photons USB port, and another terminal window with a USB converter on Serial1 tx/rx pins. On app start I send a text file which contains the following(see below), then when it's sent I press "!" on the USB terminal to see what we captured. The output shows different chars captured every time.
Here is the output of the terminal after I have sent the text file, and pressed "!"
Then send it again and "!" again. So you can see its getting different char counts.
System Boot - sv: 0.6.0 - fv 1.0.0
Got: 371
This is the serial test for trying to see if it hiccups #1
Thiis the serial test for trying to see if it hiccups #2
This is is the serial test for trying to see if it hiccups #4
This is ts the serial test for trying to see if it hiccups #6
This is ts the serial test for trying to see if it hiccups #8
This is ts the serial test for trying to see if it hiccups #10
Got: 365
This is the serial test for trying to see if it hiccups #1
Thi serial test for trying to see if it hiccups #2
This is the se serial test for trying to see if it hiccups #4
This is the serserial test for trying to see if it hiccups #6
This is the serserial test for trying to see if it hiccups #8
This is the serserial test for trying to see if it hiccups #10
Here is the text file I am sending to mimic a device sending data.
This is the serial test for trying to see if it hiccups #1
This is the serial test for trying to see if it hiccups #2
This is the serial test for trying to see if it hiccups #3
This is the serial test for trying to see if it hiccups #4
This is the serial test for trying to see if it hiccups #5
This is the serial test for trying to see if it hiccups #6
This is the serial test for trying to see if it hiccups #7
This is the serial test for trying to see if it hiccups #8
This is the serial test for trying to see if it hiccups #9
This is the serial test for trying to see if it hiccups #10
And here is my code:
//https://docs.particle.io/reference/firmware/photon/#system-thread
SYSTEM_THREAD(ENABLED);
//**************************************************************************
//
//
//**************************************************************************
void setup()
{
Serial.begin(115200);
Serial1.begin(9600);
delay(4000);
Serial.printf("\r\n************************************\r\n"); Serial.printf("System Boot - "); Serial.printf("sv: %s", System.version().c_str()); Serial.printf(" - fv 1.0.0"); Serial.printf("\r\n************************************\r\n");
}
char temp[1024];
uint16_t loc=0;
uint16_t t;
//**************************************************************************
//**************************************************************************
void serialEvent1()
{
// Grab all the data from Serial1 before its 64 byte buffer fills
while(Serial1.available() > 0)
{
// read the incoming byte:
temp[loc] = Serial1.read();
if(++loc == 1024)
{
loc=0;
}
}
}
//**************************************************************************
//**************************************************************************
void loop()
{
// Check USB serial to see if we want to print the result yet if(Serial.available()) { // If ! is pressed if(Serial.read() == 0x21) { //Show how many chars we captured Serial.printf("Got: %u\r\n", loc);
for(t=0;t<loc;t++) { Serial.print(temp[t]); }
// Now reset it for the next go arround loc=0; } }
delay(125);
}