Determine when UART is done

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User3847
Level 3
Level 3
Hello there!

I am writing a little 485 driver and I need to know when the transmission of the last byte has been done.

My current approach is:

* I schedule via GPDMA the bytes to send and retain in a variable how much bytes are pending to be actually sent.
* I have assigned to an SR the buffer shift event so I know when a byte has left the UART. I just decrement the previous variable and when it is 0, I wait a little and then change the 485 TX enable pin.

I am seeing lots of problems when I put breakpoints in higher-level code (it seems I loose some interrupts) and I have fear that, given how the code has a lot of critical sections which disabe interrupts, I might be loosing one of those interrupts.

The question is: Is there an event/interrupt that just signals transmission end (buffer empty)? This would be better.

And as a side question: When the breakpoint stops the program: do the peripherals stop working? DMA too?

Thanks
0 Likes
5 Replies
Not applicable
Hi sblanco,

You can use the FIFO transmit buffer interrupt to indicated that your FIFO is empty.
First, set the trigger limit to ONE (1) and TBCTR.LOF = 0.
This means when the transmit FIFO is falling below ONE, the interrupt will trigger.
0 Likes
User3847
Level 3
Level 3
Would that be correct? I want the interrupt to change the TX enable pin and deactivate the 485 driver, and I understood this interrupt fires just when the character is extracted from the fifo, not when all the character bits have been sent.
0 Likes
User3847
Level 3
Level 3
Just tried the suggestion and it doesn't work, although it is preferable to what I had earlier because when I was debugging and using many breakpoints some interrupts were "lost" and the byte counter never reached zero 😞

Right now and I am doing a little wait on the interrupt to ensure the last byte has been sent, but if I don't waita that little bit the interrupt fires just when the last byte is going to be transmitted.

Any other ideas?
0 Likes
Not applicable
Hi sblanco,

How about MSLS signal? Is that suit your needs?
MSLS signal is used to indicated the activation of Chip Select signal.
It will set (1) when the transmission is started and clear (0) when the transmission ended.
0 Likes
Not applicable
Hi,

i also need a solution to enable/disable the Tx-Receive/Driver from an MAX485.
Which interrupt can I use, because the FIFO Transmit interrupt doesn' t works!

Michael
0 Likes