STM32 HAL UART Interrupt unable to receive data

57 Views Asked by At

I am trying to use the uart interrupt function on STM32F030xx series MCU. The initialization for uart is done using STM32cubeide, global interrupt enabled. Have already tested using HAL_UART_Transmit function and able to view the data on an UART handler software on PC. However when I try to send the data from PC to MCU, the __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) != RESET does not seems go to SET. The code is as follows:

extern unsigned char usart2_rx_buf[100];                
extern unsigned char usart2_rx_temporary[100];          
extern unsigned char usart2_rd_len;                 
extern unsigned char usart2_rd_lentemp;             
extern unsigned char usart2_rx_enableflag;              
extern unsigned char usart2_rx_checkrightflag;          
extern unsigned short usart2_executeflag;               
extern unsigned short check;                            
extern uint8_t i, j;
extern uint16_t check_temp, res;
unsigned char test_buf[3] = {0x01, 0x02, 0x03};

extern SPI_HandleTypeDef hspi1;
extern SPI_HandleTypeDef hspi2;
extern UART_HandleTypeDef huart2;

void USART2_IRQHandler(void)
{
  /* USER CODE BEGIN USART2_IRQn 0 */
  if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) != RESET)
      {
          HAL_UART_Transmit(&huart2, test_buf, 3, HAL_MAX_DELAY);
          res = (uint8_t)(huart2.Instance->RDR & 0xFF);
//...Rest of the code

Same as mentioned above, I tried to send the data from PC to MCU but there is no received data on my UART handler display. I am expecting the content from test_buf array.

0

There are 0 best solutions below