示例#1
0
int main(){
   cout << "Starting the RPi MAX7219 example" << endl;
   SPIDevice *max = new SPIDevice(0,1);
   max->setSpeed(10000000);              // max speed is 10MHz
   max->setMode(SPIDevice::MODE0);

   // turn on the display and disable test mode -- just in case:
   max->writeRegister(0x0C, 0x01);
   max->writeRegister(0x0F, 0x00);
   max->writeRegister(0x0B, 0x07);       // set 8 digit mode
   max->writeRegister(0x09, 0xFF);       // set decode mode on all

   for(int i=1; i<9; i++){
      max->writeRegister((unsigned int)i, 0x0A); // clear to dashes
   }

   for(int i=0; i<=100000; i++){
      int val = i;
      unsigned int place = 1;
      while(val>0){
        max->writeRegister( place++, (unsigned char) val%10);
        val = val/10;
      }
//    usleep(1000);
   }
   max->close();
   cout << "End of the RPi MAX7219 example" << endl;
   return 0;
}
示例#2
0
int main(){
   cout << "Starting EBB SPI ADC Example" << endl;
   SPIDevice *busDevice = new SPIDevice(1,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(400000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   send[0] = 0b00000110; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display
   busDevice->transfer(send, receive, 3);
   cout << "Response bytes are " << (int)receive[1] << "," << (int)receive[2] << endl;

   // Use the 8-bits of the second value and the two LSBs of the first value
   int value = combineValues(receive[1]&0b00001111, receive[2]);
   cout << "This is the value " << value << " out of 4096." << endl;
   cout << "End of EBB SPI ADC Example" << endl;
}
示例#3
0
int main(){
   SPIDevice *busDevice = new SPIDevice(1,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(4000000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   int samples[SAMPLES];

   send[0] = 0b00000001; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0b10000000; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display

   for(int i=0; i<SAMPLES; i++){
   	busDevice->transfer(send, receive, 3);
        samples[i] = (short((receive[1]&0b00000011))<<8)|(short(receive[2]));
   }
   for(int i=0; i<SAMPLES; i++){
        cout << i << " " << samples[i] << endl;
   }
}
示例#4
0
int main(){
//   cout << "Starting RPi SPI ADC Multi Example" << endl;
   SPIDevice *busDevice = new SPIDevice(0,0); //Using second SPI bus (both loaded)
   busDevice->setSpeed(3900000);      // Have access to SPI Device object
   busDevice->setMode(SPIDevice::MODE0);

   unsigned char send[3], receive[3];
   int samples[SAMPLES];

   send[0] = 0b00000001; // The Start Bit followed
   // Set the SGL/Diff and D mode -- e.g., 1000 means single ended CH0 value
   send[1] = 0b10000000; // The MSB is the Single/Diff bit and it is followed by 000 for CH0
   send[2] = 0;          // This byte doesn't need to be set, just for a clear display

   for(int i=0; i<SAMPLES; i++){
   	busDevice->transfer(send, receive, 3);
        samples[i]=combineValues(receive[1]&0b00000011, receive[2]);
   }
//   cout << "The samples that were captured are:" << endl;
   for(int i=0; i<SAMPLES; i++){
        cout << i << " " << samples[i] << endl;
   }
//   cout << "\nEnd of RPi SPI ADC Example" << endl;
}