现在我们做下串口的程序:
我们先查看串口的定义引脚,如下电路图所示:
打开MCC,进行外设的初始化设置:
GPIO设置:
USART1设置:
中断设置:
时钟设置还是与上例相同:
生成代码,我们修改下main函数,让它将我们输入的数据打印出数据:
- // Enable the Global Interrupts
- INTERRUPT_GlobalInterruptEnable();
- printf("Enter any string: ");
- do{
- data = UART1_Read(); // Read data received
- UART1_Write(data); // Echo back the data received
- }while(!UART1_DataReady); //check if any data is received
下载,查看:
我们查看自动生成的接收函数:
|