cancel
Showing results for 
Search instead for 
Did you mean: 

transmitting array of integers over UART using DMA

manoritesameer
Associate II
Posted on June 07, 2014 at 00:06

I have to transfer 1000 integer elements stored in an array. How do i transfer over UART using DMA.

Please let me know, its urgent

Regards

Sameer  

#dma
2 REPLIES 2
jpeacock2399
Associate II
Posted on June 07, 2014 at 00:36

Okay, 1000 integers (we'll assume 32 bit) will be 4000 bytes.  Set up the DMA channel memory to the start of the buffer, length to 4000 bytes, peripheral to USART DR port, memory and peripheral to byte width.  Set up the USART for baud rate, etc. and enable DMA.  Do not enable USART TX interrupts.  The enable the DMA channel and it will send 4000 bytes (in binary, not ASCII) to the external device.  Enabling the DMA TC interrupt will notify you when it is complete.

Since your data transfer is a multiple of 4, if you have an STM32F2 or better you can use the FIFO mode to reduce bus contention.  Set the FIFO for 4 beats (4 bytes at a time) and the threshold to 1/4.  If your buffer is word aligned you can also use packing/unpacking with the FIFO to load 32 bytes (4 words x 4 bytes) in a 4 beat burst.  Set memory width to word (pack FIFO), peripheral stays at byte (unpack) FIFO and count to 1000 (1000 words x 4 bytes).

Your external device should be synchronized to expect a burst of binary data.  You can use an idle period before sending as a start of frame mark.  The integers will arrive in little-endian order so be sure your device can reverse byte order if it uses big-endian 32-bit integers.

  Jack Peacock
Posted on June 07, 2014 at 00:41

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/CPU%2cDMA%20UART%20Transfer%20Independently&currentviews=29]Cross posting

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..