cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H750VB_UART_Interrupt not receiving data after several cycles and after that it never receives data till the board is reset

nanotronicsnss
Associate II

I am developing a fuel dispenser and it consists of five boards and the main control of the dispenser is CPU board and the fuel dispensing pulses comes from PULSER board and all the data input comes from KEYPAD board. All the boards are maintained at same frequency and the baud rate used is 57600. The dispenser gives the data to a PC through MODBUS protocol and it gives authorization every 200ms for dispensing fuel .

CPU has three UARTS enabled

UART3- PULSER

UART2-KEYPAD and DISPLAY

UART5 - for MODBUS

the problem I am experiencing is that

UART2 and UART3 receives data for few cycles and after that it stops receiving and the data reception stops till the CPU board is reset. But the data transfer from UART5 is happening without a problem .Kindly guide through this so that the problem can be solved

UART IT Priorities set are

__HAL_UART_ENABLE_IT(&huart2,UART_IT_RXNE);// Keypad RS485

 HAL_NVIC_SetPriority(USART2_IRQn,3, 0);

 HAL_NVIC_EnableIRQ(USART2_IRQn);

 NVIC_EnableIRQ(USART2_IRQn);  // Enable IRQ for UART4 in NVIC

 HAL_GPIO_WritePin(KEYPAD_DE_GPIO_Port,KEYPAD_DE_Pin,GPIO_PIN_SET);// Enable keypad recevie

 HAL_GPIO_WritePin(KEYPAD_RE_GPIO_Port,KEYPAD_RE_Pin,GPIO_PIN_SET);// Enable keypad recevie

 __HAL_UART_ENABLE_IT(&huart3,UART_IT_RXNE);// Pulser RS485

 HAL_NVIC_SetPriority(USART3_IRQn,2, 0); // 1

 HAL_NVIC_EnableIRQ(USART3_IRQn);

 NVIC_EnableIRQ(USART3_IRQn);  // Enable IRQ for UART4 in NVIC

 HAL_GPIO_WritePin(PULSER_DE_GPIO_Port,PULSER_DE_Pin,GPIO_PIN_SET); // Enable pulser receive

 HAL_GPIO_WritePin(PULSER_RE_GPIO_Port,PULSER_RE_Pin,GPIO_PIN_SET); // Enable pulser receive

 __HAL_UART_ENABLE_IT(&huart5,UART_IT_RXNE);// modbus RS485

 HAL_NVIC_SetPriority(UART5_IRQn,1, 0); // 2

 HAL_NVIC_EnableIRQ(UART5_IRQn);

 NVIC_EnableIRQ(UART5_IRQn);  // Enable IRQ for UART4 in NVIC

 HAL_GPIO_WritePin(BACK_LIGHT_GPIO_Port, BACK_LIGHT_Pin, GPIO_PIN_SET);//Backlight ON for LCD

 HAL_GPIO_WritePin(AUTO_M_DE_GPIO_Port, AUTO_M_DE_Pin, GPIO_PIN_SET); //UM.R for modbus

 HAL_GPIO_WritePin(AUTO_M_RE_GPIO_Port, AUTO_M_RE_Pin, GPIO_PIN_SET); //UM.R for modbus

 DATA to be received in this format

Starting 32 bit - ****

Data - 128 bit encrypted data (CBC)

Stop 32 Bit - ####

RECEIVE Code at interrupt is

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 */

 HAL_UART_Receive(&huart2,&keypad_data,1,1000);//recevie serial Serial

  

if((keypad_data==0x2A)&&(keypad_inc==0))// Start bit

{

keypad_data_****+=1;// INC FOR START BIT

if(keypad_data_****>=4)// COUNT START BIT 4 TIMES 2A

{

keypad_receive_bit=1;//Enable data recevie bit

}

}

 if((keypad_receive_bit==1)&&(keypad_inc

 if((keypad_data==0x23)&&(keypad_inc>=17))// Stop bit

{

keypad_data_****+=1; // INC FOR STOP BIT

if(keypad_data_****>=8)// COUNT STOP BIT 4 TIMES 23

{

keypad_receive_bit=2;// recevie data end

keypad_inc=0;// CLR inc count

keypad_data_****=0;// Clr start and stop counter

}

}

 /* USER CODE END USART2_IRQn 1 */

}

/**

 * @brief This function handles USART3 global interrupt.

 */

void USART3_IRQHandler(void)

{

 /* USER CODE BEGIN USART3_IRQn 0 */

 /* USER CODE END USART3_IRQn 0 */

 HAL_UART_IRQHandler(&huart3);

 /* USER CODE BEGIN USART3_IRQn 1 */

 HAL_UART_Receive(&huart3,&pulser_data,1,20);//recevie serial data

 //pulse_data1=1;

if((pulser_data==0x2A)&&(pulser_inc==0))// Start bit

{

pulser_data_****+=1;// INC FOR START BIT

if(pulser_data_****>=4)// COUNT START BIT 4 TIMES 2A

{

pulser_receive_bit=1;//Enable data recevie bit

//pulse_data2=1;

}

}

if((pulser_receive_bit==1)&&(pulser_inc

if((pulser_data==0x23)&&(pulser_inc>=17))// Stop bit

{

pulser_data_****+=1;// INC FOR STOP BIT

if(pulser_data_****>=8)// COUNT STOP BIT 4 TIMES 23

{

pulser_receive_bit=2;// recevie data end

pulser_inc=0;// CLR inc count

pulser_data_****=0;// Clr start and stop counter

//pulse_data4=1;

}

 }

 /* USER CODE END USART3_IRQn 1 */

}

3 REPLIES 3
MM..1
Chief III
**
 * @brief This function handles USART3 global interrupt.
 */
void USART3_IRQHandler(void)
{
 /* USER CODE BEGIN USART3_IRQn 0 */
 
 /* USER CODE END USART3_IRQn 0 */
 HAL_UART_IRQHandler(&huart3);
 /* USER CODE BEGIN USART3_IRQn 1 */
 HAL_UART_Receive(&huart3,&pulser_data,1,20);//recevie serial data

Calling blocking receive in ISR handler never work good.

What if you reset and reconfigure the UART? If that doesn't work, perhaps an electrical latch-up issue.​

Does the UART flag an overrun, framing or noise error that you're not clearing?

A​s noted, calling blocking functions in interrupts is very poor style, and can be compounded if the timeout clock fails to advance.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I have changed the receive function using an interrupt and also updated the priorities of the UART function. the coding looks to be stable now and its working till now. I just need a clarity in assigning the priority of the UARTS..

__HAL_UART_ENABLE_IT(&huart2,UART_IT_RXNE);// Keypad RS485

  HAL_NVIC_SetPriority(USART2_IRQn,2, 2);

  HAL_NVIC_EnableIRQ(USART2_IRQn);

  NVIC_EnableIRQ(USART2_IRQn);  // Enable IRQ for UART4 in NVIC

  __HAL_UART_ENABLE_IT(&huart3,UART_IT_RXNE);// Pulser RS485

  HAL_NVIC_SetPriority(USART3_IRQn,1, 1); // 1

  HAL_NVIC_EnableIRQ(USART3_IRQn);

  NVIC_EnableIRQ(USART3_IRQn);  // Enable IRQ for UART4 in NVIC

  __HAL_UART_ENABLE_IT(&huart5,UART_IT_RXNE);// modbus RS485

  HAL_NVIC_SetPriority(UART5_IRQn,3, 3); // 2

  HAL_NVIC_EnableIRQ(UART5_IRQn);

  NVIC_EnableIRQ(UART5_IRQn);  // Enable IRQ for UART4 in NVIC