I am having a problem with the arduino nano every dropping a byte or 2 after sending several packets, it doesn't seem to matter what baud rate I'm set to 9600-115200 it still frequently drops bytes.
Currently the data is being sent as a union of a struct and a buffer.
typedef struct ARC_Struct{
uint8_t zero;
uint8_t magic;
uint8_t zero2;
uint8_t magic2;
// uint32_t count;
uint32_t curr_dt;
int32_t d_t;
int16_t servo_enc;
int16_t motor_enc;
};
union ARC_Union{
struct ARC_Struct data;
uint8_t buffer[sizeof(struct ARC_Struct)];
};
I am sending using this code:
if(Serial.availableForWrite()){
Serial.write(packet.buffer, sizeof(union ARC_Union));
}
The packet is 16 bytes long, the first 4 bytes are to identify the start of the packed and make sure all of the received bytes are aligned using 0x00 0xFD 0x00 0xFD.
The receiving end checks that those four bytes are aligned in the buffer then adds the final 12 bytes in the proper sequence.
I get a random count of clean packets between 30-60 then I normally get a corrupted one caused by a dropped byte or two.
I dumped about 10 seconds of binary values read from the uart. I haven't determined a specific pattern to which bytes are dropped just that it happens abnormally frequently.
I have tried to delay the loop to prevent over filling of the buffer based on the baud rate and packet size but it doesn't help. Anybody have any idea why the nano every has this UART issue, I read that for some of the other Arduino boards that there is a timing issue with imprecise crystals? Makes me wonder what the point is including a UART if it can't meet the timing standards for reliability?
Since I'm using the USB UART TTYACM0 there's no way I can verify the period on an oscilloscope. Anybody know what's going on?