cancel
Showing results for 
Search instead for 
Did you mean: 

What is the procedure to setup Uart Transmission in One shot mode with a DMA?

CLeo.1
Senior II

Hi guys,

for some reason I can't this working for the life of me.

I am trying to implement a DMA with Uart Transmission with a one shot, reason being is that I noticed with the DMA on circular mode it just transfers whatever is in the buffer even theres nothing in it so its just sending 0's. I want it to control the timing of when to transmit data, like once the buffer as a real value in it.

Nothing been working for me. Things i have tried are

  1. Initially the DMA is disabled for Uart Transmit
  2. Write to the Buffer not TDR but the buffer thats affiliated with the DMA
  3. Enable DMA for Uart Transmission
  4. Wait for TC flag to set
  5. Clear the TC flag
  6. Disable DMA buffer

However this lead to receiving garbage values on the other end.

The problems I have occurred is that TC flag gets stuck on the second send, or the transmissions sends twice and not once.

Any ideas?

4 REPLIES 4
TDK
Guru

The procedure you described should work, although you need to set up the DMA and UART correctly. Note that you don't need to disable the DMA as it will disable itself when the transmission is complete.

There are many examples for UART + DMA you can follow. Here is one at random (since you didn't specify a chip or family):

https://github.com/STMicroelectronics/STM32CubeF4/blob/b5abca20c9676b04f8d2885a668a9b653ee65705/Projects/STM324xG_EVAL/Examples/UART/UART_Hyperterminal_DMA/Src/main.c

> it just transfers whatever is in the buffer even theres nothing in it so its just sending 0's.

Why would it not transfer 0s? How can the DMA possibly know that a 0 value is invalid in your mind?

If you feel a post has answered your question, please click "Accept as Solution".
CLeo.1
Senior II

"you need to set up the DMA and UART correctly"

  • I mean, this is true, I would assume so as when I put it in Circ mode it works as expected, and the Rx mode of the Uart is working perfectly

"that you don't need to disable the DMA as it will disable itself when the transmission is complete."

  • This is true, correct. I dont have to

I am using the STM32H7 family.

Why would it not transfer 0s? How can the DMA possibly know that a 0 value is invalid in your mind?

Let me further explain, I didnt mean to say its invalid I mean its the not way I want it. Thats all.

I am using bare metal, so not sure how far ill get with HAL in that example

CLeo.1
Senior II

And just to further expand, that example has a buffer already filled. I am talking about when the initial buffer is empty and x time later the buffer will get filled eventually.

CLeo.1
Senior II

and to futher explain, if I enable Circ mode, it works when the buffer is initially empty it will print zero, then when I access a function that populates the buffer with a '1' it will then print out 1's. In single shot mode, nothing works. It wont send the proper value and unexpected behavior happens