UART Write Delay

I’ve noticed on SC13 (haven’t looked on other chips yet) that there is a significant delay when using UART.Write. In the attached screenshot if you look at the two traces circled in red you’ll see the following:

  • Blue arrow: The code line immediately before UART.Write which enables an RS485 TX Driver.
  • Gap between blue arrow and start of the first 19 byte transmission is 3.4ms
  • Gap between 2nd blue arrow and the start of the second 170 byte transmission is 35.8ms

It looks like the UART.Write takes time to ‘prepare’ the Write, which varies according to the size of the write. Is that expected? It seems like a long time on the 170 byte transmission (more than twice as long as the actual Write).

Any ideas for improving that? I lose a fair bit of available bandwidth on my bus because of it.

I think we delay a bit to buffer up data before sending for an overall better performance (fewer interruptus). I am not sure if flush will hep in this case.

@Dat_Tran any ideas?

I have checked code in firmware and don’t see any weird that cause the delay.

But, because UART also use interrupt to write, so if any other thread that disable interrupt that cause uart delay sending.

Could you please check only uart to see if any delay?

Thanks Dat. Looks like it does only happen on a busy CPU. It works very quickly in an application with only uart.write regardless of the write size. I’ll try to reproduce in an example project because it does always vary according to write size in production and so it doesn’t quite seem like a random delay caused by other threads, it’s very consistent.