根据原理图,USART1_TX和PC4相连,USART1_RX和PC5相连。
int fputc(int c, FILE *stream)
{
huart1.Instance->TDR=c;
while( !(huart1.Instance->ISR&1<<7)){}
return c;
}
3.2 串口中断
void USART1_IRQHandler(void)
{
uint8_t c;
HAL_UART_IRQHandler(&huart1);
c=huart1.Instance->RDR;//接收数据
huart1.Instance->TDR=c;
}
3.3 主函数
串口接线:
运行结果:



