cancel
Showing results for 
Search instead for 
Did you mean: 

USART and DMA (for RS485)

Thomas_Socomec
Associate II
Posted on January 16, 2012 at 16:56

Hello all,

I am using DMA to manage the TX line of one USART (RX stays on standard interrupt). I have no problem with a RS232 tranceiver. But when I use a RS485 tranceiver I got a problemwith the CBUS line management. I manage this output in the DMA_IT_TC interrupt. It appears that the interrupt comes 2 characters before the real end of the transmission, and so my last 2 characters are cutted by the tranceiver. I fund that if I wait for the end of transmission on the USART peripheral like that :

while
(USART_GetITStatus(cUARTPeriphDesc[eUART_PERIPH_USART3].Base, USART_IT_TC) 
EQ RESET)

the problem is solved, but I don't want to use infinite loop. I think there is somewhere a settings I have forgot ... Do you have an idea ? Thanks Thomas STM32F103 #dma #uart #usart-dma-rs485
5 REPLIES 5
Posted on January 16, 2012 at 18:04

Don't bother with the DMA TC interrupt, use the USART TC interrupt instead, as it signals when the last bit leaves the USART shift register, not when the last byte gets placed in the USART's holding register (TXE) at ~16 bit cycles before TC for 8-bit bytes.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Thomas_Socomec
Associate II
Posted on January 17, 2012 at 11:25

Thank you for your answer Clive1.

If I enable the USART TC interrupt, the DMA does not work anymore. Maybe a problem of DMA settings ?

Moreover, the USART TC interrupt occurs after each bytes transmission, and I want to avoid that. That's why I am trying to use the DMA on this usart (only one interrupt at the end of transfert).

I think I will rather use a timer to change my input state after the transmission.

jpeacock2399
Associate II
Posted on January 17, 2012 at 16:20

Use the interrupts in tandem.  Wait for the DMA interrupt first, and then enable the UART end of transmission  interrupt in the DMA service routine.  That way you know when the transmiter is finished and you can turn around the RS-485 transceiver safely.

  Jack Peacock
Thomas_Socomec
Associate II
Posted on February 09, 2012 at 12:00

Thanks for your help, all is working fine now.

Thomas

stm32forum
Associate II
Posted on February 13, 2012 at 10:37

Hi thomas,

Maybe you can share (a part of) your code, it's not clear to me how you did it.

Thanks,

Evert