AnsweredAssumed Answered

STM32F103T8 usart2 corrupted data

Question asked by edling_huven.mikael on Sep 28, 2011
Latest reply on Jun 15, 2012 by alhaidar.hasan

Im trying to get the usart2 working but for some reason I get random corrupted data when I send message to the STM32F103T8. I can send messages from the STM32 to the computer without any corrupted bytes but not the other way around.

The usart2 is piping the received messages to a DMA. I've activated the usart2 in the following way:

      DMA_InitStructure.DMA_PeripheralBaseAddr = USART2_DR_Base;    
      DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)gRXBuf2;      //Define in usart2.h
      DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
      DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
      DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
      DMA_InitStructure.DMA_BufferSize = RX_BUF_SIZE2;               //Define in usart2.h
      DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
      DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
      DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;             
      DMA_Init( DMA1_Channel6, &DMA_InitStructure );

           USART_InitStructure2.USART_BaudRate = 4800;
       USART_InitStructure2.USART_WordLength = USART_WordLength_8b;
           USART_InitStructure2.USART_StopBits = USART_StopBits_1;
           USART_InitStructure2.USART_Parity = USART_Parity_No;
           USART_InitStructure2.USART_HardwareFlowControl =       USART_HardwareFlowControl_None;
          USART_InitStructure2.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

          /* Configure USART2 */
          USART_Init(USART2, &USART_InitStructure2);

         /* Enable USART2 Receive and Transmit interrupts */
      // Enable USART2 Receive DMA requests
      // Enable DMA1 USART RX channel
      DMA_Cmd(DMA1_Channel6, ENABLE);
          // Enable USART2
          USART_Cmd(USART2, ENABLE);

I have also enabled the usart2 clock as following:

      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

And finally enabled the usart2 interrupt:

      NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

I've done a simple program which checks when new data have been added to the DMA memory where the received data is and send the exact same data back to the computer.
Then i connect to the STM32 with the windows xp hyperterminal and sends some chars.
For example if i send GPGGA, I might get back something like GP=GA or even worse like G?G, where some chars is ''.

Does anyone have any idea what might be wrong? I would really appriciate the help.