GPIO模拟SPI通信从机代码
主函数为:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "key.h"
#include "spi.h"
#include "lcd.h"
#include "sdram.h"
unsigned char data[9]="B15020106";
int main(void)
{
u8 receivr_Data=0,i=0;
HAL_Init();
Stm32_Clock_Init(360,25,2,8);
delay_init(180);
uart_init(115200);
LED_Init();
LCD_Init();
SDRAM_Init();
POINT_COLOR=BLUE;
LCD_Clear(WHITE);
SPI_Init();
LCD_ShowString(10,40, 96,24,24,"Rx data:");
LCD_ShowString(10,80,216,24,24,"Tx data:B15020106");
while(i<9)
{
receivr_Data=SlaveSPI_read();
if(receivr_Data!=0)
{
i++;
LCD_ShowChar(106+12*(i-1),40,receivr_Data,24,0);
}
receivr_Data=0;
}
LED0=0;
SPI_MISO_H;
delay_ms(500);
i=0;
for(i=0;i<9;i++)
{
SPI_MISO_H;
while(SPI_MOSI==0)
SlaveSPI_write(data[i]);
SlaveSPI_write(data[i]);
SlaveSPI_write(data[i]);
}
while(1)
{
}
1