#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
int main(void)
{
unsigned char date[2],rec[2];
int spiChannel = 0;
int clock = 1000000;
int speed = clock;
int mode = 3;
if ((wiringPiSPISetupMode (spiChannel, speed, mode)))
{
printf("SPI set error!
");
return -1;
}
printf("Starting SPI Test
");
printf("Write:
");
date[0]=0x80;//寄存器地址
date[1]=0x55;//要写的数据
wiringPiSPIDataRW(0,date,2);
printf("date[0] : %d ",date[0]);
printf("date[1] : %d
",date[1]);
delay(500);
printf("Read:
");
rec[0]=0x00;//寄存器地址
rec[1]=0x00;
wiringPiSPIDataRW(0,rec,2);
printf("rec[0] : %d ",rec[0]);
printf("rec[1] : %d
",rec[1]);//返回的数据是这个
return 0;
}