Skip to main content
julienterrier39
Associate III
August 25, 2015
Question

Usart_interrupt

Posted on August 25, 2015 at 21:34

Hello, I work with a STM32F429ZIT Âµcontroller and I have a set back. I wish find someone who could explain me what's happening in details in this part of the prog:

                                                

/** @brief  Enable the specified UART interrupt.

  * @param  __HANDLE__: specifies the UART Handle.

  *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or

  *         UART peripheral.

  * @param  __INTERRUPT__: specifies the UART interrupt source to enable.

  *          This parameter can be one of the following values:

  *            @arg UART_IT_CTS:  CTS change interrupt

  *            @arg UART_IT_LBD:  LIN Break detection interrupt

  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt

  *            @arg UART_IT_TC:   Transmission complete interrupt

  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt

  *            @arg UART_IT_IDLE: Idle line detection interrupt

  *            @arg UART_IT_PE:   Parity Error interrupt

  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)

  * @retval None

  */

#define UART_IT_MASK  ((uint32_t)0x0000FFFF)

#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \

(((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & UART_IT_MASK)): \

((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))

    This topic has been closed for replies.

    11 replies

    julienterrier39
    Associate III
    September 5, 2015
    Posted on September 05, 2015 at 23:32

    Hi Shahrzad,

    Everything is clear now, I found function which call

    void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)

    and I understood how work the Nested Vector Interrupt Controller:

    /* Definition for USARTx's NVIC */
    #define USARTx_IRQn USART1_IRQn
    #define USARTx_IRQHandler USART1_IRQHandler

    So when an interrupt comes the µcontroller is locked because the vector suited at the interrupt worked! Then we use this fonction to execute an interrupt:

    void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
    {
    uint32_t tmp1 = 0, tmp2 = 0;
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_PE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_PE); 
    /* UART parity error interrupt occurred ------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    { 
    __HAL_UART_CLEAR_PEFLAG(huart);
    huart->ErrorCode |= HAL_UART_ERROR_PE;
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_FE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
    /* UART frame error interrupt occurred -------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    { 
    __HAL_UART_CLEAR_FEFLAG(huart);
    huart->ErrorCode |= HAL_UART_ERROR_FE;
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_NE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
    /* UART noise error interrupt occurred -------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    { 
    __HAL_UART_CLEAR_NEFLAG(huart);
    huart->ErrorCode |= HAL_UART_ERROR_NE;
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_ORE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
    /* UART Over-Run interrupt occurred ----------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    { 
    __HAL_UART_CLEAR_OREFLAG(huart);
    huart->ErrorCode |= HAL_UART_ERROR_ORE;
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE);
    /* UART in mode Receiver ---------------------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    { 
    UART_Receive_IT(huart);
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_TXE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE);
    /* UART in mode Transmitter ------------------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    {
    UART_Transmit_IT(huart);
    }
    tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_TC);
    tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC);
    /* UART in mode Transmitter end --------------------------------------------*/
    if((tmp1 != RESET) && (tmp2 != RESET))
    {
    UART_EndTransmit_IT(huart);
    }
    if(huart->ErrorCode != HAL_UART_ERROR_NONE)
    {
    /* Set the UART state ready to be able to start again the process */
    huart->State = HAL_UART_STATE_READY;
    HAL_UART_ErrorCallback(huart);
    } 
    }

    And if we are in UART mode transmitter end we execute this function:

    static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
    {
    /* Disable the UART Transmit Complete Interrupt */ 
    __HAL_UART_DISABLE_IT(huart, UART_IT_TC);
    /* Check if a receive process is ongoing or not */
    if(huart->State == HAL_UART_STATE_BUSY_TX_RX) 
    {
    huart->State = HAL_UART_STATE_BUSY_RX;
    }
    else
    {
    /* Disable the UART Parity Error Interrupt */
    __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
    /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
    __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
    huart->State = HAL_UART_STATE_READY;
    }
    HAL_UART_TxCpltCallback(huart);
    return HAL_OK;
    }

    To finishHAL_UART_TxCpltCallback(huart); is called! For the attribut _weak I found several information therefore now I understood how to use it! thank you