標(biāo)題: 兩個(gè)STM32單片機(jī)之間串口通信的程序 [打印本頁(yè)]

作者: cenyufu    時(shí)間: 2024-9-9 14:46
標(biāo)題: 兩個(gè)STM32單片機(jī)之間串口通信的程序
實(shí)現(xiàn)兩個(gè)STM32F103單片機(jī)之間的串口通信

單片機(jī)源程序如下:
  1. #include "led.h"
  2. #include "sys.h"
  3. #include "usart1.h"
  4. #include "usart2.h"
  5. #include "stdio.h"
  6. #include "delay.h"

  7. int main(void)
  8. {
  9.         int16_t i=0;
  10.         LED_Init();
  11.         usart1_Init(115200);
  12.    usart2_Init(115200);
  13.         LED = 1;

  14.         //在這個(gè)while不斷的循環(huán)
  15.         while(1)
  16.         {
  17.                 printf("i=%d\r\n",i);
  18.                 Delay_ms(1000);
  19.                 i++;
  20. //                if(USART1_STA & 0x8000)
  21. //                {
  22. //                        LED = 0;
  23. //                        //表示成功接收到數(shù)據(jù)
  24. //                        //發(fā)回來(lái)電腦屏幕
  25. //                        USART1_Send_data((char *)USART1_REC,USART1_REC_MAX);
  26. //                       
  27. //                        //發(fā)給另一個(gè)單片機(jī)
  28. //                        USART2_Send_data((char *)USART1_REC,USART1_REC_MAX);
  29. //                        USART1_STA &=~(0x8000);
  30. //                }
  31.         }

  32. }


復(fù)制代碼


原理圖: 無(wú)
仿真: 無(wú)
代碼: 兩個(gè)STM32的串口通信.7z (190.98 KB, 下載次數(shù): 9)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1