Skip to content
Extraits de code Groupes Projets
spi.cpp 796 octets
Newer Older
  • Learn to ignore specific revisions
  • Diego de Fauconval's avatar
    spi
    Diego de Fauconval a validé
    #include <stdlib.h>
    #include <stdio.h>
    #include <wiringPi.h>
    #include <wiringPiSPI.h>
    
    #include <iostream>
    
    using namespace std;
    
    const int CHANNEL_CAN = 1;
    
    int main(int argc, char const *argv[])
    {
        int result, fd;
        unsigned char buff[30];
    
        fd = wiringPiSPISetup(CHANNEL_CAN, 500000);
        if (fd == -1) {
            printf("Error setup\n");
            exit(EXIT_FAILURE);
        }
    
    
        int reg = 0x42;
    
        int GPIO[] = {0b00000001, 0b00000010, 0b00001000, 0b00010000};
        buff[0] = reg;
        for (int i = 0; i < 4; i++) {
            buff[1] = GPIO[i];
            printf("buff %i : %x %x\n",i, buff[0], buff[1]);
            result = wiringPiSPIDataRW(CHANNEL_CAN, buff, 2);
            printf("buff %i : %x %x\n",i, buff[0], buff[1]);
            buff[0] = reg;
            delay(1500);
        }
        
    
    Diego de Fauconval's avatar
    spi
    Diego de Fauconval a validé
    
        return 0;
    }