2020-03-16 09:32 AM
Hi all, Thanks for the support and sharing the experience.
I have generated the code using STM32 CubeMx and using UART5 in interrupt mode. UART5 interrupt is configured to receive interrupt for every 1byte of data reception. Snap of the code is below.
Observation : UART interrupt handler function call stop after start some time
Kindly verify that UART interrupt function is implemented without any violation.
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN1_Init();
MX_CAN2_Init();
MX_I2C1_Init();
MX_I2C2_Init();
MX_SPI1_Init();
MX_TIM4_Init();
MX_UART4_Init();
MX_UART5_Init();
MX_TIM10_Init();
MX_USART6_UART_Init();
MX_TIM14_Init();
MX_RTC_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT (&huart4, &g__MAIN_UART4_RxByte, DEF_MAIN_UART4_RX_BUFFER_SIZE);
HAL_UART_Receive_IT (&huart6, &g__MAIN_UART6_RxByte, DEF_MAIN_UART6_RX_BUFFER_SIZE);
//This method is to configure the UART5 Receiver in the non-blocking mode
HAL_UART_Receive_IT(&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
}
void UART5_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart5);
}
void HAL_UART_RxCpltCallback (UART_HandleTypeDef * huart)
{
if(huart->Instance == UART4)
{
//<Function call to store the received data>
HAL_UART_Receive_IT (&huart4, &g__MAIN_UART4_RxByte, DEF_MAIN_UART4_RX_BUFFER_SIZE);
}
if(huart->Instance == USART6)
{
//<Function call to store the received data>
HAL_UART_Receive_IT (&huart6, &g__MAIN_UART6_RxByte, DEF_MAIN_UART6_RX_BUFFER_SIZE);
}
if(huart->Instance == UART5)
{
//<Function call to store the received data>
HAL_UART_Receive_IT (&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART6)
{
}else if(huart->Instance == UART4)
{
}else if(huart->Instance == UART5)
{
if(HAL_UART_GetError(huart) != HAL_UART_ERROR_NONE)
{
nErrorCode = HAL_UART_GetError(huart);
State = HAL_UART_GetState(huart);
}
}
}
Additional Info:
I required to receive GPS data over UART (\r\n+QGPSGNMEA: $GPGGA,060418.00,1257.506345,N,07744.637410,E,1,03,3.0,889.6,M,-85.0,M,,*4F\r\n) periodically every 500millisecond and other messages as well.
2020-03-16 10:08 AM
Perhaps it is not receiving anything?
You're going to have to review functionality of all code, check peripheral and GPIO settings in the debugger. Make sure UART and pins are properly set up and clocked.
Try sending patterns with interrupts, confirm other aspects of the plumbing.
2020-03-16 11:20 PM
Hi Clive1, Thanks for the support and response.
Perhaps it is not receiving anything?
No, UART interrupt works for some time (5 bytes length data packet in the interval of 200millisecond is received) then stops receiving the interrupt.
I came across the this thread https://community.st.com/s/question/0D50X00009XkfrW/cubemx-uart-receive-complete-interrupt . Will this help me in resolving the issue.
2020-03-16 11:31 PM
>then stops receiving the interrupt
How do you know?
What are exactly the symptoms?
JW
2020-03-17 12:44 AM
Dear waclawek.jan, Thanks for the support.
How do you know?
What are exactly the symptoms?
//Interrupt is cofigured to trigger on reception of 1 Byte of data
#define DEF_MAIN_UART5_RX_BUFFER_SIZE 1
uint8_t g__MAIN_UART5_RxByte = 0;
void HAL_UART_RxCpltCallback (UART_HandleTypeDef * huart)
{
if(huart->Instance == UART5)
{
//<Function call to store the received data>
/***** TOGGLING LED HERE *******/
HAL_UART_Receive_IT (&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
}
}
Note : I am able to see LED blinking for some time and then stops even data is received in the UART Rx line
2020-03-17 12:55 AM
You have a simple choice:
For the latter here are good instructions: