cancel
Showing results for 
Search instead for 
Did you mean: 

Usart DMA Rx and timer input capture reset

pcu
Associate II
Posted on December 22, 2015 at 13:57

Hello,

I configured my STM32F4 like in the AN3109 where USART uses DMA for

reception

and RX pin is connected to a timer (input capture reset mode) because I do not know the size of incoming messages (modbus).

So far so good, it works.

But in the example of AN3109, timer is disabled (in the interrupt) after the timeout  and I do not see how it activates again.

It's a bit my problem:

-If I do not disable the timer after timeout there will be a multitude of interrupt in case of long period without message.

-If I disable the timer I do not see how to reactivate it for the begin of the next frame.

Any ideas?

Thank you.
5 REPLIES 5
jpeacock
Associate II
Posted on December 22, 2015 at 18:58

The arrival of the next RX message can be indeterminate, so restarting the timer isn't sufficient as it may time out before a new message is started from the remote connection.

The solution I use is to set up a regular USART RX interrupt for the first character of the message.  Once it arrives I know an incoming message is in progress so I can switch to DMA for the rest of the message and start the timer to detect the end.  DMA and the timer can be configured before the message starts so the switch to DMA mode occurs quickly once the first character arrives.

  Jack Peacock

Posted on December 23, 2015 at 12:23

Once Rx is connected to a timer channel, can't it be used also to start the timer, in trigger mode?

JW
jpeacock
Associate II
Posted on December 23, 2015 at 14:06

Rx is already being used to reset the timer when data arrives.  The timer is free running after the first data byte arrives, constantly reset on bit transitions in Rx, and then times out when there's no more serial data to trigger a reset.  I'm not sure if it's possible to both start and reset a timer on the same trigger, never tried it.

  Jack Peacock

pcu
Associate II
Posted on December 23, 2015 at 14:50

Thank you for your replies.

I thought this:

After the timeout I reconfigure the timer input in GPIO EXTI mode.

At the beginning of the next frame, in the interrupt EXTI I reconfigure the input in timer capture mode.

Posted on December 23, 2015 at 15:40

OK, and what about this: set up the whole capture/trg-to-reset stuff, and TIMx_ARR and the interrupt on update (= timeout), but don't enable the timer yet. Enable DMA on the capture channel in TIMx_DIER and set up the respective DMA channel to circular mode, NDTR=1, to transfer one halfword from RAM or FLASH into TIMx_CR1, and store a halfword into that position in RAM or FLASH, containing the content of TIMx_CR1 with CEN and OPM bits set to 1.

This should work ''out of the box'' without any software intervention needed.

JW