2017-08-14 04:47 AM
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
2017-08-26 05:43 PM
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.
2017-08-27 01:51 AM
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