AnsweredAssumed Answered

STM32F103 Usart receive strange problem

Question asked by nowrozi.daniel on May 25, 2015
Latest reply on May 26, 2015 by nowrozi.daniel
Hi there,

I try to send data from PC to my stm32 board using RS232 but each time I send data to stm I get exactly same strange other data for sample:
if i send 0x12 i receive 0xc4 always
and if i send 0x2f i receive 0x3f , i dont understand what is buggy here

this is my code for initialization
// USART Initialization
void enableUsart()
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 |
                                                     RCC_APB2Periph_AFIO |
                                                     RCC_APB2Periph_GPIOA , ENABLE);
     
        GPIO_InitTypeDef GPIO_InitStruct;
        GPIO_StructInit (& GPIO_InitStruct);
        // Initialize USART1_Tx
        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA , &GPIO_InitStruct);
        // Initialize USART1_RX
        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA , &GPIO_InitStruct);
     
        USART_InitTypeDef USART_InitStructure;
        // Initialize USART structure
        USART_StructInit (& USART_InitStructure);
        // Modify USART_InitStructure for non -default values , e.g.
        // USART_InitStructure.USART_BaudRate = 38400;
        USART_InitStructure.USART_BaudRate = 19200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_Init(USART1 ,&USART_InitStructure);
        USART_Cmd(USART1 , ENABLE);
         
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    /* Enable USART1 global interrupt */
    NVIC_EnableIRQ(USART1_IRQn);
         
//      NVIC_InitTypeDef NVIC_InitStructure;
//      // No StructInit call in API
//      NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
//      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
//      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
//      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//      NVIC_Init (& NVIC_InitStructure);
}

and this is interrupt function
void USART1_IRQHandler(void)
{
        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
        {
                uint8_t data;
                // buffer the data (or toss it if there 's no room
                // Flow control will prevent this
                data = USART_ReceiveData(USART1);
                             
                parseMessage(data);            
        }
        if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
        {
                uint8_t data;
                /* Write one byte to the transmit data register */
                if (uq_dequeue (&UART1_TXq, &data)){
                        USART_SendData(USART1, data);
                } else {
                        // if we have nothing to send , disable the interrupt
                        // and wait for a kick
                        USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
                        TxPrimed = 0;
                }
        }
}

thanks in advance

Outcomes