实现两个STM32F103单片机之间的串口通信
单片机源程序如下:- #include "led.h"
- #include "sys.h"
- #include "usart1.h"
- #include "usart2.h"
- #include "stdio.h"
- #include "delay.h"
- int main(void)
- {
- int16_t i=0;
- LED_Init();
- usart1_Init(115200);
- usart2_Init(115200);
- LED = 1;
- //在这个while不断的循环
- while(1)
- {
- printf("i=%d\r\n",i);
- Delay_ms(1000);
- i++;
- // if(USART1_STA & 0x8000)
- // {
- // LED = 0;
- // //表示成功接收到数据
- // //发回来电脑屏幕
- // USART1_Send_data((char *)USART1_REC,USART1_REC_MAX);
- //
- // //发给另一个单片机
- // USART2_Send_data((char *)USART1_REC,USART1_REC_MAX);
- // USART1_STA &=~(0x8000);
- // }
- }
- }
复制代码
原理图: 无
仿真: 无
代码:
两个STM32的串口通信.7z
(190.98 KB, 下载次数: 9)
|