cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt callback function is not called after Transmission of data in UARTS2 communication

MSHAM.1
Associate II

I am using STM32L451RCTx in STM32CubeIDE. I need to response through usart2 for the received request on the same usart2. I am receiving the request one time and can able respond for that. After the transmission of the response, I am not able to receive the request. Usart2 receive interrupt is not called whenever data received on the usart lines.

--> In Init side,

static void MX_USART2_UART_Init(void)

{

 /* USER CODE BEGIN USART2_Init 0 */

 /* USER CODE END USART2_Init 0 */

 /* USER CODE BEGIN USART2_Init 1 */

 /* USER CODE END USART2_Init 1 */

 huart2.Instance = USART2;

 huart2.Init.BaudRate = 9600;

 huart2.Init.WordLength = UART_WORDLENGTH_8B;

 huart2.Init.StopBits = UART_STOPBITS_1;

 huart2.Init.Parity = UART_PARITY_NONE;

 huart2.Init.Mode = UART_MODE_TX_RX;

 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart2.Init.OverSampling = UART_OVERSAMPLING_16;

 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN USART2_Init 2 */

 if(HAL_UART_Receive_IT(&huart2, &uart2_buffer_u8, 1))

 {

 Error_Handler();

 }

 /* USER CODE END USART2_Init 2 */

}

--> In Interrupt handler side,

void USART2_IRQHandler(void)

{

 /* USER CODE BEGIN USART2_IRQn 0 */

 /* USER CODE END USART2_IRQn 0 */

HAL_UART_IRQHandler(&huart2);

 /* USER CODE BEGIN USART2_IRQn 1 */

CLEAR_BIT(huart2.Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));

/* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */

CLEAR_BIT(huart2.Instance->CR3, USART_CR3_EIE);

/* Rx process is completed, restore huart->RxState to Ready */

huart2.RxState = HAL_UART_STATE_READY;

/* Clear RxISR function pointer */

huart2.RxISR = NULL;

uint8_t status = 0;

status = HAL_UART_Receive_IT(&huart2, &uart2_buffer_u8, 1);

if (status || huart2.ErrorCode != 0 || huart2.ErrorCode != 34) {

/* error handler */

/* Re-Initialize to avoid missing of messages */

status = HAL_UART_Receive_IT(&huart2, &uart2_buffer_u8, 1);

if (status) {

/* error handler */

}

}

//USART_ClearITPendingBit(&huart2,USART_IT_TC);

 /* USER CODE END USART2_IRQn 1 */

}

--> Interrupt Call back function

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {

if(huart->Instance == USART2)

{

mgmtLocalRx = uart2_buffer_u8;

if ((mgmtLocalRx == FRAMEHEAD) && (mgmtBMS_RxCounter != 0)) {

mgmtBMS_RxCounter = 0;

mgmtBMS_Rx_Buffer[mgmtBMS_RxCounter++] = mgmtLocalRx;

}

else if ((mgmtLocalRx == FRAMEHEAD) && (mgmtBMS_RxCounter == 0)) {

mgmtBMS_Rx_Buffer[mgmtBMS_RxCounter++] = mgmtLocalRx;

}

else if ((mgmtBMS_RxCounter < 5) && (mgmtBMS_RxCounter != 0)){

mgmtBMS_Rx_Buffer[mgmtBMS_RxCounter++] = mgmtLocalRx;

}

else if ((mgmtLocalRx == FRAMEEND) && (mgmtBMS_RxCounter >= 5)){

mgmtBMS_Rx_Buffer[mgmtBMS_RxCounter++] = mgmtLocalRx;

uartRxSection = true;

mgmtBMS_RxCounter = 0;

}

}

}

Anybody knows how to fix this issue, Please help to fix this.

5 REPLIES 5
gbm
Lead III

Remove the code from USART ISR, starting with  /* USER CODE BEGIN USART2_IRQn 1 */

Most of this (fiddling with int sources) is not needed, the rest should be moved to callback.

Anyway, I will never understand why the people use HAL USART services which are almost unusable in real world.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Cube/HAL as such is usable only for a very limited number of problems, arguably the typical ones. But the comfort of clicking and lack of proper examples and leadership prevails.

JW​

thanks for reply

i have changed, but still remains same.

Usart2 receive interrupt is not called whenever data received on the usart lines.

Does the receiver work? Isn't it stuck with overflow?

​JW

MSHAM.1
Associate II

thanks,

 I am receiving the request one time at beginning and can able respond for that. After the transmission of the response, I am not able to receive the request.

Please, how to check the overflow.