Skip to main content
Visitor II
November 5, 2008
Question

UART TX finished interrupt needed

  • November 5, 2008
  • 12 replies
  • 2570 views
Posted on November 05, 2008 at 22:02

UART TX finished interrupt needed

    This topic has been closed for replies.

    12 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:45

    Thanks rgreenthal!

    I did think about using a timer and calculating the transmit time, but in the end I opted for the following:

    Set up DMA to transmit. Put the Uart in loopback mode

    Set up DMA to recieve the same length as transmitted, and then interrupt.

    Set up DMA linked list to then recieve any subsequent response.

    In the interrupt after the first recieve (i.e the looped back transmit),

    I poll the uart until it is idle (i.e. for the duration of the stop bit)

    and then turn of the transmit enable.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:45

    Thank you all for the discussion. I've been tearing my hair out trying to figure out how to do it. I did the BUSY-polling method, but that didn't work, since the latency was too high and the peer on the RS485 was replying before I could turn the bus direction around. I was about to use a timer (that would trigger after the last TX interrupt), but that seemed messy.

    I believe that the best solution is just to use the Loop Back (as Paul Smitton figured out) and basically use the RX interrupt to deal with the problem of the TX interrupt. I am not using DMA, but just normal interrupts. This works great!

    Basically, turn on UART0->CR |= LBE, set a counter for the number of bytes in the outgoing packet, set a flag meaning ''write'' mode is asserted, and finally enable TX mode on the RS485 bus.

    Then in the ISR, check if ''write'' mode is asserted, and if it is, then decrement the counter. When it hits 0, then disable LBE, disable TX mode and unset the flag meaning ''read'' mode.

    Works great! Thanks Paul.

    -Mark