PDA

View Full Version : Determine when UART is done



sblanco
Sep 12th, 2013, 11:33 AM
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

Jackson
Sep 16th, 2013, 02:53 AM
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.

sblanco
Sep 27th, 2013, 04:31 AM
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.

sblanco
Oct 1st, 2013, 10:26 AM
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?

Jackson
Oct 4th, 2013, 12:08 AM
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.

Michael Schoppe
Nov 12th, 2013, 07:51 AM
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