AnsweredAssumed Answered

STM32L4 - LL_USART_TransmitData8 trigger RXNE

Question asked by maciel.vinicius on Apr 10, 2018
Latest reply on Apr 10, 2018 by maciel.vinicius

Hello,

I am having a problem with RX interrupt. Everytime I call LL_USART_TransmitData8() it triggers RXNE flag. I enabled only RXNE , ERROR and disabled TXE. Also, If I send bytes to UART does not trigger RXNE interrupt.

I am running the firmware with freeRTOS, so maybe is a priority problem? UART priority is 6 = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORIT(5) + 1.

void Configure_Modem_USART(void)
{
  /* Enable the peripheral clock of GPIO Port */
  MODEM_USARTx_GPIO_CLK_ENABLE();

  /* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
  LL_GPIO_SetPinMode(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_MODE_ALTERNATE);
  MODEM_USARTx_SET_TX_GPIO_AF();
  LL_GPIO_SetPinSpeed(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
  LL_GPIO_SetPinOutputType(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
  LL_GPIO_SetPinPull(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_PULL_UP);

  /* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
  LL_GPIO_SetPinMode(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_MODE_ALTERNATE);
  MODEM_USARTx_SET_RX_GPIO_AF();
  LL_GPIO_SetPinSpeed(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
  LL_GPIO_SetPinOutputType(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
  LL_GPIO_SetPinPull(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_PULL_UP);

  /* (2) NVIC Configuration for USART interrupts */
  /*  - Set priority for USARTx_IRQn */
  /*  - Enable USARTx_IRQn */
  NVIC_SetPriority(MODEM_USARTx_IRQn,
                   configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY+1);
  NVIC_EnableIRQ(MODEM_USARTx_IRQn);

  /* (2) Enable USART peripheral clock and clock source ***********************/
  MODEM_USARTx_CLK_ENABLE();
  /* Set clock source */
  MODEM_USARTx_CLK_SOURCE();

  /* (3) Configure USART functional parameters ********************************/
 
// HAL configuration
    USART_ModemHandle.Instance = MODEM_USARTx_INSTANCE;

     USART_ModemHandle.Init.BaudRate = 115200;
     USART_ModemHandle.Init.WordLength = USART_WORDLENGTH_8B;
     USART_ModemHandle.Init.StopBits = USART_STOPBITS_1;
     USART_ModemHandle.Init.Parity = USART_PARITY_NONE;
     USART_ModemHandle.Init.Mode = UART_MODE_TX_RX;
    //USART_ModemHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
     USART_ModemHandle.Init.CLKPolarity = USART_POLARITY_HIGH;
     USART_ModemHandle.Init.CLKPhase = USART_PHASE_1EDGE;
     USART_ModemHandle.Init.CLKLastBit = USART_LASTBIT_ENABLE;

     if (HAL_USART_Init(&USART_ModemHandle) != HAL_OK) {}

     /* Enable RXNE and Error interrupts, disable TX */

    LL_USART_EnableIT_RXNE(MODEM_USARTx_INSTANCE);
    LL_USART_EnableIT_ERROR(MODEM_USARTx_INSTANCE);
    LL_USART_DisableIT_TXE(MODEM_USARTx_INSTANCE);
}

Interrupt handler

void MODEM_USARTx_IRQHandler(void)
{
    __IO uint32_t received_char;

    if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_ORE) // Overrun Error
        MODEM_USARTx_INSTANCE->ICR = USART_ICR_ORECF;

    if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_NE) // Noise Error
        MODEM_USARTx_INSTANCE->ICR = USART_ICR_NCF;

    if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_FE) // Framing Error
        MODEM_USARTx_INSTANCE->ICR = USART_ICR_FECF;

    /* Check RXNE flag value in ISR register */
    if(LL_USART_IsActiveFlag_RXNE(MODEM_USARTx_INSTANCE) &&
        LL_USART_IsEnabledIT_RXNE(MODEM_USARTx_INSTANCE))
    {
        /* RXNE flag will be cleared by reading of RDR register (done in call) */
        if (idx_rx < BUF_SIZE) {
            received_char =
                LL_USART_ReceiveData8(MODEM_USARTx_INSTANCE);
            recv_buff[idx_rx++] = received_char;
        }
        else
            idx_rx = 0;
    }
    else
    {
        /* Call Error function */
        //Error_Callback();
    }
}

Outcomes