cancel
Showing results for 
Search instead for 
Did you mean: 

UART and DMA to send data

philipp239955
Associate II
Posted on November 20, 2009 at 06:39

UART and DMA to send data

6 REPLIES 6
philipp239955
Associate II
Posted on May 17, 2011 at 13:30

Hi

I just ran an modified USART example DMA_Interrupt from the StdPeriph_Examples.

USART1 data sent by DMA and recieved by recieve-interrupt.

It works fine the first time.

but here's my question:

how to trigger/start a DMA transfer again?

I tried to disable and enable the DMA channel and DMA-request.

Are there any flags to be reset?

In comment from the example it says, that the DMA will be triggered by a Tx event. What does that mean? I don't have the TX-interrupt enabled. so how to generate an Tx event?

thanks for any help

Philipp

[ This message was edited by: philipp.hofstetter on 19-11-2009 15:25 ]

armmcu
Associate II
Posted on May 17, 2011 at 13:30

Hi,

A DMA transfer of a single data will start as soon as the the TXE bit is set again.

In the Refman TXE bit is set by hardware when the content of the TDR register has been transferred into the shift register.

Cheers.

philipp239955
Associate II
Posted on May 17, 2011 at 13:30

Hi, thanks for the reply.

Right, TXE shows that TDR is empty. After my DMA transfer to the UART peripheral is complete the TXE is already set. DO I have to reset or set another flag?

What I want to do is to initiate another DMA transfer. But not automatically, therefore the DMA-channel is defined as noncircular.

armmcu
Associate II
Posted on May 17, 2011 at 13:30

Hi,

As it's stated in ST documentation:

If the channel is configured in noncircular mode, no DMA request is served after the last transfer (that is once the number of data items to be transferred has reached zero). In order to reload a new number of data items to be transferred into the DMA_CNDTRx register, the DMA channel must be disabled.

Note that: If a DMA channel is disabled, the DMA registers are not reset. The DMA channel registers(DMA_CCRx, DMA_CPARx and DMA_CMARx) retain the initial values programmed during the channel configuration phase.

Hence to to initiate another DMA transfer as you want:

-Disable the used DMA channel

-Reload the new transfer data size (to so this just the update this field in the ''DMA_InitStructure'', and than update the structure using DMA_Init () function).

philipp239955
Associate II
Posted on May 17, 2011 at 13:31

Hi. thanks it works!

I haven't read the manual carefully enough.

It works fine to disable the DMA-channel, write the new size to the CNTDR and Enable the DMA channel again. no need to call the whole DMAInit function.

I din't made it in that order before:

Code:

DMA_Cmd(UART1_Tx_DMA_Channel, DISABLE);

UART1_Tx_DMA_Channel->CNDTR = 50; //set the number of data to send

DMA_Cmd(UART1_Tx_DMA_Channel, ENABLE);

armmcu
Associate II
Posted on May 17, 2011 at 13:31

Perfect!