实现两个STM32F103单片机之间的SPI通信
单片机源程序如下:- #include "stm32f10x.h" // Device header
- #include "oled.h"
- #include "delay.h"
- #include "MySPI_Master.h"
- #include "MySPI_Slave.h"
- //主机行为
- int main(void)
- {
- OLED_Init();
- MySPI_Master_Init();
- OLED_ShowString(1,1,"SPI MASTER");
-
- uint16_t sData=108, rData;
- while(1)
- {
- OLED_ShowString(2,1,"S:");
- OLED_ShowNum(2,3,sData,5);//当前发送的数据
-
- rData=MySPI_Master_SendReceive16bit(sData);
- OLED_ShowString(3,1,"R:");
- OLED_ShowNum(3,3,rData,5);//当前接收的数据
-
- sData=sData+10;//+10再发送给从机
- Delay_ms(1000);
- }
- }
- /***
- //从机行为
- int main(void)
- {
- OLED_Init();
- MySPI_Slave_Init();
- OLED_ShowString(1,1,"SPI Slave");
-
- uint16_t rData;
- while(1)
- {
- rData=MySPI_Slave_GetrData();
- OLED_ShowString(2,1,"R:");
- OLED_ShowNum(2,3,rData,5);//当前接收到的数据
-
- OLED_ShowString(3,1,"S:");
- OLED_ShowNum(3,3,rData+3,5);//+3再发送给主机
- }
- }
- ***/
复制代码
原理图: 无
仿真: 无
代码:
两个STM32的SPI通信.7z
(180.71 KB, 下载次数: 8)
|