SPI编程

#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!\n");
return -1;
}

printf("Starting SPI Test\n");
printf("Write:\n");
date[0]=0x80;//寄存器地址
date[1]=0x55;//要写的数据
wiringPiSPIDataRW(0,date,2);
printf("date[0] : %d ",date[0]);
printf("date[1] : %d \n",date[1]);
delay(500);
printf("Read:\n");
rec[0]=0x00;//寄存器地址
rec[1]=0x00;
wiringPiSPIDataRW(0,rec,2);
printf("rec[0] : %d ",rec[0]);
printf("rec[1] : %d \n",rec[1]);//返回的数据是这个
return 0;
}

posted on 2017-11-17 09:20  玲珑子  阅读(811)  评论(0编辑  收藏  举报

导航