AnsweredAssumed Answered

F103 USART1 RX IRQ happens premature.

Question asked by marsh.randy on Dec 26, 2015
Latest reply on Dec 27, 2015 by marsh.randy
I am using the USART1 interface of an F103 and I'm havin trouble getting interrupts correctly. When receiving a byte the first interrupts get triggered while bit 6 is still underway and then a second interrupt happens for some unknown reason.

row1 is debug pin that is being toggled ever irq
row2 is rx pin
row3 is tx pin
http://imgur.com/IgfKKvJ

void USART1_Init(void)
{
    /* USART configuration structure for USART1 */
    USART_InitTypeDef usart1_init_struct;
    /* Bit configuration structure for GPIOA PIN9 and PIN10 */
    GPIO_InitTypeDef gpioa_init_struct;


    /* Enalbe clock for USART1, AFIO and GPIOA */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO |
                           RCC_APB2Periph_GPIOA, ENABLE);


    /* GPIOA PIN9 alternative function Tx */
    gpioa_init_struct.GPIO_Pin = GPIO_Pin_9;
    gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
    gpioa_init_struct.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &gpioa_init_struct);
    /* GPIOA PIN9 alternative function Rx */
    gpioa_init_struct.GPIO_Pin = GPIO_Pin_10;
    gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
    gpioa_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &gpioa_init_struct);


    /* Baud rate 9600, 8-bit data, One stop bit
     * No parity, Do both Rx and Tx, No HW flow control
     */
    usart1_init_struct.USART_BaudRate = 9600;
    usart1_init_struct.USART_WordLength = USART_WordLength_8b;
    usart1_init_struct.USART_StopBits = USART_StopBits_1;
    usart1_init_struct.USART_Parity = USART_Parity_No ;
    usart1_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    usart1_init_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(USART1, &usart1_init_struct);






    /* Enable RXNE interrupt */
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);


    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);


    /* Enable USART1 global interrupt */
    NVIC_EnableIRQ(USART1_IRQn);


    /* Enable USART1 */
    USART_Cmd(USART1, ENABLE);
}

void USART1_IRQHandler(void)
{
     static int tx_index = 0;
     static int rx_index = 0;
     static char rx_byte;


    if(USART_GetITStatus(USART1, USART_IT_RXNE))
    {
         rx_byte=USART1->DR;
         if(rx_byte != 'x')
         {
              USART_SendData(USART1, rx_byte);
         }


         /*telemetry_rx_buffer[rx_index++] = USART_ReceiveData(USART1);
         if (rx_index >= (sizeof(telemetry_rx_buffer) - 1))
              rx_index = 0;*/
         debugpin_cycle();
    }
}


What am i doing wrong here?

Outcomes