cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Transfer Complete and USART Transfer Complete

Diez.R.
Associate II
Posted on August 14, 2017 at 13:47

Hi all:

I have been using DMA with USARTs for years on STM32F4xx and STM32F0xx microcontrollers, but mainly with full-duplex connections like RS-232. Now I need to handle RS-485, which is only half-duplex. My code needs to manually switch the RS-485 transceiver from rx to tx, and viceversa.

The main problem I am facing is that the 'DMA Transfer Complete' interrupt will trigger before the 'USART Transfer Complete', right? After the DMA transfer is complete, I need to wait until the USART has sent all bits before switching RS-485 back to reception mode. I haven't found yet any examples about the best way to do this, and I know interrupt handling can be tricky.

Can anybody help?

Thanks in advance,

  R. Diez

2 REPLIES 2
Posted on August 27, 2017 at 02:43

Several thoughts.  One is to look at the system status and see if the gstatus is set to ready, another would be to use the callback (look in the HAL module if you use it, then look for TXcomplete callback or RX complete callback, then write your own routines to set a flag or the like as needed).

Have a somewhat similar problem with receiving a variable length message with a usart, trying idle time detection.  Would work on receive only, I think.

Jack Peacock
Associate II
Posted on August 27, 2017 at 10:51

I use a two-stage interrupt.  In the DMA interrupt handler when TC occurs (assuming no DMA errors) enable the USART TC interrupt and disable DMA IRQ.  When the USART TC occurs the shift register is empty and it's safe to switch direction on the transceiver.

  Jack Peacock