AnsweredAssumed Answered

Receive interrupt problem in STM32F103ZET6

Question asked by Ehsan SH on Feb 7, 2016
Latest reply on Feb 14, 2016 by Clive One
Hello guys,
I 'm a new STM32 user that started using and learning STM32 MCUs developing .
I have circuit that I have a usart connection at usart2.
I can transmit data from MCU perfectly and also I can receive data easily but after a few receiving data from the usart , my receive interrupt doesn't run.
In addition , my project generated by STMCUBEMx.


my code is :
"
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
__HAL_UART_FLUSH_DRREGISTER(&huart2);
HAL_UART_Transmit(&huart2,(_8bit_var*)"  interrupt 1  ",sizeof("  interrupt 1  "),100);
HAL_UART_Receive_IT(&huart2,data,5);
}
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();


  /* Configure the system clock */
  SystemClock_Config();


  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();


  /* USER CODE BEGIN 2 */
  HAL_UART_Receive_IT(&huart2,data,5);
  //int cun = 0;
HAL_GPIO_WritePin(BT_KEY_GPIO_Port,BT_KEY_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED3_GPIO_Port,LED3_Pin,GPIO_PIN_SET);
HAL_GPIO_WritePin(LED4_GPIO_Port,LED4_Pin,GPIO_PIN_SET);
HAL_Delay(500);
  /* USER CODE END 2 */


  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
       HAL_GPIO_TogglePin(LED3_GPIO_Port,LED3_Pin);
      delay_ms(100);   //works exactly like HAL_Delay(); 
      HAL_GPIO_TogglePin(LED4_GPIO_Port,LED4_Pin);
      delay_ms(100);
      HAL_UART_Transmit(&huart2,data,5,100);
      delay_ms(20);


      int cu;
     for (cu = 0;cu <5;cu++)
     {
          data[cu] = 0;
     }
}
  /* USER CODE END WHILE */


  /* USER CODE BEGIN 3 */
if (HAL_GPIO_ReadPin(S4_GPIO_Port,S4_Pin)==GPIO_PIN_RESET)
     {
     HAL_GPIO_WritePin(BT_KEY_GPIO_Port,BT_KEY_Pin,GPIO_PIN_SET);


     HAL_UART_Transmit(&huart2,(_8bit_var*)"  mydata  ",sizeof("  mydata  "),100);
     }
else{
     HAL_UART_Transmit(&huart2,(_8bit_var*)"    our data   ",sizeof("    our data   "),100);
}


  }
  /* USER CODE END 3 */


}



"  

Outcomes