cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VE USART DMA RECEIVE

HNguy.6
Associate II

Hello everyone, I am a beginner on STM32F4. I want to using DMA for receiving data via USART. But it doesnot work, please help me to solve the problem. Here is my code:

void USART2_ConfigDMA(void)

{

  DMA_InitTypeDef DMA_InitStructure;

  RCC->AHB1ENR = RCC_AHB1ENR_DMA1EN;

  DMA_InitStructure.DMA_BufferSize = 10;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ;

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USART2->DR)) ;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;

  DMA_InitStructure.DMA_Channel = DMA_Channel_4 ;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ;

  DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&data[0]; 

  DMA_Init(DMA1_Stream5,&DMA_InitStructure);

  USART_Cmd(USART2, ENABLE);

  USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);

  DMA_Cmd(DMA1_Stream5, ENABLE);

}

Thanks for your support !

1 ACCEPTED SOLUTION

Accepted Solutions

Probably want to start by ORing clock enable bits, rather than blind writing..

RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;

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

View solution in original post

3 REPLIES 3

Probably want to start by ORing clock enable bits, rather than blind writing..

RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;

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

Thank you ! I have solved the problem.

I have one more problem. I cannot received data continuously using DMA, please help me !:

  while(1)

  {

    if (USART_GetFlagStatus(USART2, USART_FLAG_IDLE)==RESET)

    { 

      /* clear buffer */

      clear_buffer(SEMEATECH_RECEIVE);

      // USART_Cmd(USART2, ENABLE);

      USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);

      DMA_Cmd(DMA1_Stream5, ENABLE);

    }

    else if (USART_GetFlagStatus(USART2, USART_FLAG_IDLE)==SET)

    {

      // USART_Cmd(USART2, DISABLE);

      USART_DMACmd(USART2, USART_DMAReq_Rx, DISABLE);

      DMA_Cmd(DMA1_Stream5, DISABLE);

      UART_DISPLAY_DATA(10);

    }

    delay_ms(500);

  }