コード例 #1
0
ファイル: test.cpp プロジェクト: o0osorentoo0o/LinuxCNC
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;
}
コード例 #2
0
ファイル: ADCmulti2.cpp プロジェクト: 19Dan01/exploringBB
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;
   }
}
コード例 #3
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;
}