AnsweredAssumed Answered

UART4 DMA Rx Problem

Question asked by EYIGEL.Levent on Apr 4, 2014
Latest reply on Apr 4, 2014 by Clive One
I cannot get into DMA mode, the code  I wrote did not get into DMA  interrupt. The code I wrote is as follows. Any advice?( my processor is STM32F103ZG)

 uint8_t RxBuffer1[100]; 
 /*UART - Pin Config*/
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  DMA_InitTypeDef DMA_InitStructure;; 


  /* Clock configuration -------------------------------------------------------*/
  RCC_APB2PeriphClockCmd( UART_GPIO_CLK_TX | UART_GPIO_CLK_RX | RCC_APB2Periph_AFIO, ENABLE);
  RCC_APB1PeriphClockCmd(UART_CLK , ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
 

 /* Configure the GPIO ports( UART4 Transmit and Receive Lines) */ 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin =  UART_TxPin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(UART_GPIO_TX, &GPIO_InitStructure); 
 
/* Configure the UART4_Rx as input floating */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = UART_RxPin ;
  GPIO_Init(UART_GPIO_RX, &GPIO_InitStructure);
  
  USART_InitStructure.USART_BaudRate = 1200;
  USART_InitStructure.USART_WordLength = USART_WordLength_9b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_Even;
  USART_InitStructure.USART_HardwareFlowControl =     USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  
    /* UART Guard Time set to 16 Bit */
  USART_SetGuardTime(UART4, 8);
 
  USART_Init(UART4, &USART_InitStructure);
   /* Enable the UART4 */
  USART_Cmd(UART4, ENABLE);
  
  
  /************************* DMA *****************************/
  DMA_DeInit(DMA2_Channel3);
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)RxBuffer1; 
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // Receive 
  DMA_InitStructure.DMA_BufferSize = 1; 
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; 
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; 
  DMA_InitStructure.DMA_Priority = DMA_Priority_High; 
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
 
  DMA_Init(DMA2_Channel3, &DMA_InitStructure); 
  /* Enable the USART Rx DMA request */
  USART_DMACmd(UART4, USART_DMAReq_Rx, ENABLE);
 
  /* Enable DMA Transfer Complete interrupt */
  DMA_ITConfig(DMA2_Channel3, DMA_IT_TC, ENABLE); 
 
  /* Enable the DMA RX Stream */
  DMA_Cmd(DMA2_Channel3, ENABLE);

  /* Enable the UART4 RX DMA Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);  



/*******************************************************************/ 
void DMA2_Channel3_IRQHandler()
{
  if(DMA_GetITStatus(DMA2_IT_TC3)){
    
    Uart_Interrupt_Handler();
    
    DMA_ClearITPendingBit(DMA2_IT_TC3);
  }

Outcomes