0

I am having trouble while trying Rx interrupt using stm32l476-disco. There was no debugging error, but it didn't work. (cf: Tx is working)

I was following same process that using "STM32F4".

The following code is my stml4xx_hal_uart.c code.


    void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
    {
      uint32_t isrflags   = READ_REG(huart->Instance->ISR);
      uint32_t cr1its     = READ_REG(huart->Instance->CR1);
      uint32_t cr3its     = READ_REG(huart->Instance->CR3);
    
      uint32_t errorflags;
      uint32_t errorcode;
    
      /* If no error occurs */
      errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF));
      if (errorflags == 0U)
      {
        /* UART in mode Receiver ---------------------------------------------------*/
    #if defined(USART_CR1_FIFOEN)
        if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U)
            && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U)
                || ((cr3its & USART_CR3_RXFTIE) != 0U)))
    #else
        if (((isrflags & USART_ISR_RXNE) != 0U)
            && ((cr1its & USART_CR1_RXNEIE) != 0U))
    #endif /* USART_CR1_FIFOEN */
        {
          if (huart->RxISR != NULL)
          {
            huart->RxISR(huart);
          }
          return;
        }
      }

I think the Key is RxISR(function pointer) code. So I found the definition of this function pointer.

if (huart->RxISR != NULL)
          {
            huart->RxISR(huart);
          }
          return;

And the definition of this function point is a following code.

void (*RxISR)(struct __UART_HandleTypeDef *huart);

What can I do?

  • If using the ST HAL Driver Library you should use the Callback functions of the HAL and not the ISR function directly. Check out one of the HAL examples, they are easy to understand. – A.R.C. Jan 11 '21 at 08:56
  • Does this answer your question? [How the callback functions work in stm32 Hal Library?](https://stackoverflow.com/questions/49479148/how-the-callback-functions-work-in-stm32-hal-library) – A.R.C. Jan 11 '21 at 08:57
  • I added the following code to the main.c file ''' HAL_UART_Receive_IT(&huart2,&rx3_data, 1); HAL_UART_Transmit(&huart2, &rx3_data,1,10); ''' and '''void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { /* Prevent unused argument(s) compilation warning */ if(huart->Instance ==USART2){ HAL_UART_Receive_IT(&huart2, &rx3_data,1); }''' / I think I already use the Callback Functions of the HAL but it is not working still :( Do you know why..? Anyway, I am really thankful for your help:) – stm32l4-starter Jan 11 '21 at 15:41
  • Am I correct, that you are calling "HAL_UART_Receive_IT" from the callback function? Have you checked if the function is not returning an error code? I would recommend you call the function from your main loop (or RTOS task?) and not from ISR context. – A.R.C. Jan 12 '21 at 08:46
  • Thank you! I checked the function using led light, and it worked!!! – stm32l4-starter Jan 13 '21 at 16:56

0 Answers0