I'm trying to track down a horrible situation where when I write 32 bytes out Serial5 (115200) to a TTL<->RS485 module which then sends it to a LORA DTU - my main code halts SOMEWHERE in a reasonably complex main loop.
Main loop typically has a per second worst case execution time of 400-20000us, and achieves 700k loops/second... When there's a write to LORA though, I see a worst case execution of 400milliseconds.
I have put simple Serial.print(micros()) at the start and end of the serial write routine and it shows that the routine completes and exits in 6-7ms. I also changed the serial5 speed to 19200 and it increased the halt to around 700ms.
I've checked the serial output buffer before and after the write (127 bytes, 99 bytes) but I can't isolate what's causing the slowdown.
My code is huge and uses various interrupts, intervaltimers and multiple simultaneous serial ports (Nextion screen, GPS, RS485 adaptor, thermal printer) so isolating this will be a pain. I am hoping that perhaps I am coming across a well known quirk which is immediately obvious to more experienced programmers than I.
Specifically, is there any way I can determine if the serial (specifically serial5) port is in fact what is blocking execution? The fact that I can reliably change the length of time blocking by adjusting the data rate from 19200 to 115200 indicates that it's likely to be that. Also, when I leave the rest of the code exactly as is, and JUST comment out literally the lines as follows...
The code blocking disappears.
I _know_ the right answer is to recreate this in a simple scenario but I fear that this would absolutely not happen without the rest of the code running and I'd rather attempt to identify what's causing the blocking to start with. (There's about 6000 lines in total)
Any ideas?
Cheers - Neil G
Main loop typically has a per second worst case execution time of 400-20000us, and achieves 700k loops/second... When there's a write to LORA though, I see a worst case execution of 400milliseconds.
I have put simple Serial.print(micros()) at the start and end of the serial write routine and it shows that the routine completes and exits in 6-7ms. I also changed the serial5 speed to 19200 and it increased the halt to around 700ms.
I've checked the serial output buffer before and after the write (127 bytes, 99 bytes) but I can't isolate what's causing the slowdown.
My code is huge and uses various interrupts, intervaltimers and multiple simultaneous serial ports (Nextion screen, GPS, RS485 adaptor, thermal printer) so isolating this will be a pain. I am hoping that perhaps I am coming across a well known quirk which is immediately obvious to more experienced programmers than I.
Specifically, is there any way I can determine if the serial (specifically serial5) port is in fact what is blocking execution? The fact that I can reliably change the length of time blocking by adjusting the data rate from 19200 to 115200 indicates that it's likely to be that. Also, when I leave the rest of the code exactly as is, and JUST comment out literally the lines as follows...
Code:
if (loraaddr == 1) {
DEBUG_CS.print("Sending Start test request to LORA at ");
DEBUG_CS.print(local);
DEBUG_CS.print(" seconds : ");
DEBUG_CS.print(sizeof(LoraData.LoraLine));
DEBUG_CS.print("bytes - CRC : 0x");
DEBUG_CS.println(LoraData.timepacketdata.crc, HEX);
//rs485.write(start_loraADDH);
//rs485.write(start_loraADDL);
//rs485.write(start_loraCHANNEL);
//rs485.write("AB");
//rs485.write(LoraData.LoraLine, timepacketsize);
rs485lastuse = millis();
}
The code blocking disappears.
I _know_ the right answer is to recreate this in a simple scenario but I fear that this would absolutely not happen without the rest of the code running and I'd rather attempt to identify what's causing the blocking to start with. (There's about 6000 lines in total)
Any ideas?
Cheers - Neil G