AnsweredAssumed Answered

USART Interrupts in STM32F103C8

Question asked by bell.mark on Aug 3, 2011
Latest reply on Jun 28, 2014 by gage.aaron
Hello --

We're having difficulity getting USART1 and USART2 interrupts to work.

We can successfully transmit from either USART  but can not receive on either USART via interrupt notification.  Polling the USART for receive shows the data is being correctly received by the USART.

We are concentrating on USART1 for now.    With all USART1 interrupts disabled,  we never enter the USART1 interrupt handler, as expected.

When we enable the RXNE interrupt,  we always enter the USART1 interrupt,  but nothing is connected to the USART1 RX line.   Furthermore, within the ISR handler,  we're testing to see which interrupt occurred ( ORE, RXNE, TXE, TC, CTS, LBD, IDLE ,NE ,PE),  and none are active !!   This is expected as only the RXNE is enabled, but yet something is causing the USART1 handler to get called and we can't figure out what is triggering the interrupt.

Our USART1 initialization is as follows:

    USART_InitStructure.USART_BaudRate = 460800;
    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(USART1, &USART_InitStructure);

    /* Enable Overrun Error Interrupt */
    USART_ITConfig(USART1, USART_IT_ORE, DISABLE);

    /* Enable USART1 Receive Data Read To Be Read Interrupt */
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    /* Disable USART1 Transmit Data Register Empty Interrupt */
    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

    /* Enable USART1 Transmission Complete Interrupt */
    USART_ITConfig(USART1, USART_IT_TC, DISABLE);

    USART_ITConfig(USART1, USART_IT_CTS, DISABLE);
    USART_ITConfig(USART1, USART_IT_LBD, DISABLE);
    USART_ITConfig(USART1, USART_IT_IDLE, DISABLE);
    USART_ITConfig(USART1, USART_IT_PE, DISABLE);
    USART_ITConfig(USART1, USART_IT_ERR, DISABLE);

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

Our ISR is pretty basic.  For RXNE we have

    //Data available in the Read Register.
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
    {
        //Clear pending bit and read the data.
        USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    }

This snipppet is replicated for ORE,TXE,TC,CTS,LBD,IDLE,NE, and PE.

Interrupt initialization is

  /* Enable the USART1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable the USART2 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

Update to original post:

The culprit seems to be
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInit(USART1, &USART_ClockInitStructure);

The ISR does NOT get called if the ClockInit function is commented out,  yet the clock is disabled (as we're not using the USART clock (pins).

Any ideas?

Thanks

Mark

Outcomes