//Trying SPI example from Sparkfun //#include #include #include #include #include using namespace std; // LED Pin - wiringPi pin 0 is BCM_GPIO 17. // we have to use BCM numbering when initializing with wiringPiSetupSys // when choosing a different pin number please use the BCM numbering, also // update the Property Pages - Build Events - Remote Post-Build Event command // which uses gpio export for setup for wiringPiSetupSys #define LED 17 // channel is the wiringPi name for the chip select (or chip enable) pin. // Set this to 0 or 1, depending on how it's connected. static const int CHANNEL = 0; int main(void) { //wiringPiSetupSys(); //pinMode(LED, OUTPUT); int fd, result; //unsigned char buffer[100]; unsigned char buffer[100]; cout << "Initializing" << endl; printf("Initializing\n"); // Configure the interface. // CHANNEL insicates chip select, // 500000 indicates bus speed. fd = wiringPiSPISetup(CHANNEL, 5000000); //was 500000 cout << "Init result: " << fd << endl; printf("Init result: %d\n",fd); for (;;) { // clear display buffer[0] = 0xB5; buffer[1] = 0xC6; buffer[2] = 0xD7; buffer[3] = 0xE8; wiringPiSPIDataRW(CHANNEL, buffer, 4); usleep(100000); int SpiIn = (int)(buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]); printf("Spi Input %Xh\n", SpiIn); } }