cancel
Showing results for 
Search instead for 
Did you mean: 

Interupt driven uart reception not working

NJP.1
Associate III

Hi all iam working in stm32 f051c8tx microcontroller im trying to recieve a byte and if i recieve a byte in intrupt im printing "hello world " via tx of the same uart, the issue is im not able to recieve any char the below is the code any thoughts please let me know.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
   // HAL_UART_Transmit(&huart1, UART1_rxBuffer, 12, 100);
	INTERUPT_RX_1 = rx_data[0];
    HAL_UART_Receive_IT(&huart1, rx_data, 1);
}
 
 
int main(void)
{
 
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  memset(SSD1306_Buffer,0,strlen(SSD1306_Buffer));
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
 
  MX_GPIO_Init();
 
   MX_I2C2_Init();
 
  MX_SPI1_Init();
 // MX_SPI2_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();
  MX_TIM6_Init();
  MX_ADC_Init();
  MX_TIM14_Init();
 
  fsm_sens_init();
 
  RetargetInit(&huart1);
 
 
 
 
  sensor_init(&sensor_cfg);
 
  HAL_UART_Receive_IT (&huart1, rx_data, 1);
 
  while(1)
  {
 
	 // printf("while  \r\n");
	  if(INTERUPT_RX_1 != 0)
	  {
	    printf("while");
	    INTERUPT_RX_1 = 0;
	  }
  }
 
}
 
 
 
 
static void MX_USART1_UART_Init(void)
{
 
  /* USER CODE BEGIN USART1_Init 0 */
 
  /* USER CODE END USART1_Init 0 */
 
  /* USER CODE BEGIN USART1_Init 1 */
 
  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate =19200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */
 
  /* USER CODE END USART1_Init 2 */
 
}

10 REPLIES 10

Check your hardware if Pin connection is correctly or maybe shared with other functions.