/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / stm32f103vct6 usart2 reception problem with keil compiler

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 Family
  •  » stm32f103vct6 usart2 reception problem with keil compiler

# 1   2014-01-06 13:19:47 stm32f103vct6 usart2 reception problem with keil compiler

engineershrenik
New member
Registered: 2014-01-06
Posts: 1

stm32f103vct6 usart2 reception problem with keil compiler

stm32f103vct6 usart2 false RXNE flag setting and reception using keil
Hi,

I would need 3 USARTs for a project (I am using stm32f103vct6 microcontroller). One USART is already functional properly which is USART1. I am trying same with USART2. Transmit is working fine but but RXNE flag is falsely setting up here and hence its giving garbage Rx character. I tried same code using arm-none-linux-gcc compiler in which its working fine (no false RXNE flag setting), hence i thought it could be compiler related issue. I am posting my code for reference.



void USART2_Init(void)
{
                        GPIO_InitTypeDef GPIO_InitStructure;


                        USART_InitTypeDef USART_InitStructure;






                        //enable bus clocks


                        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
                        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);


                        //Set USART2 Tx (PA2) as AF push-pull


                        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;


                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;


                        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;


                        GPIO_Init(GPIOA, &GPIO_InitStructure);


                        //Set USART2 Rx (PA3) as input floating


                        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;


                        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;


                        GPIO_Init(GPIOA, &GPIO_InitStructure);


                        USART_InitStructure.USART_BaudRate = 115200;


                        USART_InitStructure.USART_WordLength = USART_WordLength_8b;


                        USART_InitStructure.USART_StopBits = USART_StopBits_1;


                        USART_InitStructure.USART_Parity = USART_Parity_No ;


                        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;


                        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;






                        USART_Init(USART2, &USART_InitStructure);


                        //Enable USART2


                        USART_Cmd(USART2, ENABLE);
}






/* Usart functions ---------------------------------  ------------------------*/
/*******************************************************************************
* Function Name  : SerialPutChar
* Description    : Print a character on the HyperTerminal
* Input          : - c: The character to be printed
* Output         : None
* Return         : None
*******************************************************************************/
void SerialPutChar(u8 c)
{
        USART_SendData(USART2, c);
        while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
}


int GetChar (void)
{
        while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
                return USART_ReceiveData(USART2);
}
/*******************************************************************************
* Function Name  : Serial_PutString
* Description    : Print a string on the HyperTerminal
* Input          : - s: The string to be printed
* Output         : None
* Return         : None
*******************************************************************************/
void Serial_PutString(u8 *s)
{
        while (*s != '\0')
        {
        SerialPutChar(*s);
        s ++;
        }
}


void main()


{
  int data;
          USART1_Init();
        Serial_PutString("This is test put string function on open source compiler\r\n");
                                  //printf("This is containing the printf debug command\r\n");
                  while(1)
                  {


                          data = GetChar();
                          SerialPutChar(data);
                  }
}

Offline

 

  • Index
  •  » STM32 Family
  •  » stm32f103vct6 usart2 reception problem with keil compiler

Board footer