2025-01-27 8:34 PM - last edited on 2025-01-30 6:24 AM by Andrew Neil
I simplified the code belows ;
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USB_DEVICE_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(1000);
// CDC_Transmit_FS(buff , sizeof(buff));
// if (user_inp[0]=='x'){
// CDC_Transmit_FS(buff , sizeof(buff));}
//
// else{
// CDC_Transmit_FS(user_inp,2);}
//readbuff[0] = user_inp[0];
//readbuff[1] = user_inp[1];
// if (user_inp[0]=='x'){
// HAL_UART_Transmit(&huart2, readbuff,sizeof(readbuff),0xff);}
//
//
// else{ HAL_UART_Transmit(&huart2, buff,sizeof(buff),0xff);}
HAL_UART_Transmit(&huart2, buff,sizeof(buff),0xff);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
the only code is uart_trans,i open two windows for uart(ttl to usb) and usb com.after i reset ,the uart trans data per second.when i send data to the usb,the uart trans stops suddenly.is there something interrupt uart?
2025-01-28 5:55 AM
Chip can only do one thing at a time. What does your USB data reception code look like? USB will interrupt whatever is happening and execute that code. HAL_UART_Transmit is blocking, so it will be pause until receive code is complete.
2025-01-30 6:01 AM
You need to enable UART interrupt in NVIC settings using CubeMX. After generating your code, you need to use HAL_UART_Transmit_IT instead of HAL_UART_Transmit to ensure non-blocking transmission of UART
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.