1.创建工程
1.1设置RCC
1.2时钟树的配置
1.3配置串口中断
然后生成工程
2.编写程序
2.1在main.c文件的主函数while循环中添加以下代码:
HAL_UART_Transmit(&huart1, (uint8_t *)"hello windows!\r\n", 16 , 0xffff);
HAL_Delay(1000);
2.2在main中,改为一下代码:
uint8_t receivedChar;
if (HAL_UART_Receive(&huart1, &receivedChar, 1, 0xffff) == HAL_OK)
{
switch (receivedChar)
{
case '#': // Pause sending message
HAL_UART_Transmit(&huart1, (uint8_t *)"stop", 16 , 0xffff);
break;
case '*': // Resume sending message
HAL_UART_Transmit(&huart1, (uint8_t *)"hello windows!\r\n", 16 , 0xffff);
HAL_Delay(1000); //??1s
break;
default: // Continue sending message
HAL_UART_Transmit(&huart1, (uint8_t *)"hello windows!\r\n", 16 , 0xffff);
HAL_Delay(1000); //??1s
break;
}
}