#include int misoPin = 50; int mosiPin = 51; int clkPin = 52; int csPin = 53; int clockRate = 1000000; // between 500kHz and 10 MHz // Word structure: 2-byte words, 16 bits. // Clock Priority = Idle Low // Clock Phase = first Edge // WHILE LISTENING TO RESPONSES FROM SENSORS, HOST SHOULD WRITE OUT A 0x0001 TO MOSI LINES TO AVOID ERRORS // FUNCTION: Prints a byte in binary with all leading 0's void printBin(byte aByte) { for (int8_t aBit = 7; aBit >= 0; aBit--) Serial.write(bitRead(aByte, aBit) ? '1' : '0'); } // FUNCTION: Sends a sample command to the SynTouch NumaTac sensors for DC Pressure. int samplePDC() { // SPI interfacing SPI.beginTransaction(SPISettings(clockRate, MSBFIRST, SPI_MODE0)); // Open up Arduino SPI channel digitalWrite(csPin, LOW); // Open comms with NT sensor SPI.transfer(0b10000011); // Sample DC Pressure Command (1st Byte) SPI.transfer(0x01); // Sample DC Pressure Command (2nd Byte) [Ignored by NumaTac] digitalWrite(csPin, HIGH);// Close comms with NT sensor delayMicroseconds(100); // Mandatory delay; Need minimum of 50 us before can read data from NumaTacs digitalWrite(csPin, LOW); // Open comms with NT sensor byte reading1 = SPI.transfer(0x01); // Send a dummy 0x01 while reading the SPI buffer. byte reading2 = SPI.transfer(0x01); // Send a dummy 0x01 while reading the SPI buffer. digitalWrite(csPin, HIGH);// Close coms with NT sensor SPI.endTransaction(); // Close Arduino SPI channel int byteHandler = 0x0000; byteHandler = ((reading1 >> 1) << 5) + (reading2 >> 3); return byteHandler; } // FUNCTION: Sends a sample command to the SynTouch NumaTac sensors for AC Pressure. int samplePAC() { // SPI interfacing SPI.beginTransaction(SPISettings(clockRate, MSBFIRST, SPI_MODE0)); // Open up Arduino SPI channel digitalWrite(csPin, LOW); // Open comms with NT sensor SPI.transfer(0b10000000); // Sample AC Pressure Command (1st Byte) SPI.transfer(0x01); // Sample AC Pressure Command (2nd Byte) [Ignored by NumaTac] digitalWrite(csPin, HIGH);// Close comms with NT sensor delayMicroseconds(100); // Mandatory delay; Need minimum of 50 us before can read data from NumaTacs digitalWrite(csPin, LOW); // Open comms with NT sensor byte reading1 = SPI.transfer(0x01); // Send a dummy 0x01 while reading the SPI buffer. byte reading2 = SPI.transfer(0x01); // Send a dummy 0x01 while reading the SPI buffer. digitalWrite(csPin, HIGH);// Close coms with NT sensor SPI.endTransaction(); // Close Arduino SPI channel int byteHandler = 0x0000; byteHandler = ((reading1 >> 1) << 5) + (reading2 >> 3); return byteHandler; }