cancel
Showing results for 
Search instead for 
Did you mean: 

USART example with interrupt (optional DMA)

ersan
Associate II
Posted on November 26, 2012 at 15:22

Hi,

I tried and I failed, now I'm asking here If someone please could provide an USART Data transmit and recieve example which uses interrupts (and if possible DMA for large datatelegrams ~ 5Kbyte). I'm using the STM32 F407 Usart2 and KEIL.

Please help

regards

5 REPLIES 5
Posted on November 26, 2012 at 15:50

Here's a USART3 IRQ example

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20USART%20receive%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=124]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F4%20USART%20receive%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=124

USART2 DMA TX example 1/2 way down, USART3 DMA TX/RX 3/4 way down

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/DMA%20Memory%20To%20UART5&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=760]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FDMA%20Memory%20To%20UART5&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=760

I've posted a bunch of other examples, but you might have to hunt them down yourself. Review the RM0090 for the DMA Streams for specific USART RX/TX operations.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ersan
Associate II
Posted on November 28, 2012 at 00:14

THANK YOU!!

ionutF
Associate III
Posted on February 15, 2016 at 12:10

Hi clive

What function  do you recommend to use  in USART_IRQ Handler when discerning which interrupt source occurred, given that I have multiple interrupt sources enabled ?  

USART_GetITStatus()  or USART_GetFlagStatus() ?

Posted on February 15, 2016 at 13:05

Either would work, from a style perspective I'd lean toward the GetITStatus.

They don't infer when or which precipitated the interrupt, and the IT status is not masked by the enablement of the source. From a functional perspective you're looking at the same latch in the peripheral logic.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 18, 2016 at 23:19

FYI, the easiest way (and I got UART6 working with DMA within minutes):

use CubeMX, configure all and create also DMA for the UART. Let the code generate, take the code (or use as reference), call the MSP Init and UART Init functions generated.

Use the HAL API function to kick off UART DMA ... and all fine, works pretty well for me. Ahhh, don't forget to implement the __weak INT handlers called when DMA has done Half or Full Complete, if you want to do something in (DMA) INT handlers (often my one are empty, enough to use the Instance->State variables updated accordingly).