I try to communicate via SPI protocol the sensor SCC2130-D08, which is a 3-axis accelerometer and x-axis gyroscope sensor of Murata, with the Adafruit Feather M0 basic microcontroller. The datasheet of the sensor is the following: https://www.murata.com/~/media/webrenewal/products/sensor/gyro/scc2000/scc2130-d08%20datasheet%2082177500b0.ashx?la=en-gb
Thr problem is that I have been trying and following other threads of this forum like the one asking for an inclinometer of Murata: Using the SPI interface to communicate with a sensor - Networking, Protocols, and Devices - Arduino Forum But with no success!
My code is similar to the post of the link of the inclinometer but slightly modified to suit the requirements of the IMU sensor:
// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 8; //Slave select(SS)
const int dataINPin = 21; //MISO
const int dataOUTPin = 19; //MOSI
const int serialClockPin = 20; //CSK
// Commands for Murata SCC2130-D08:
const byte WHOAMI = B01110100;
const byte RATE = B00000100;
void setup() {
Serial.begin(9600);
// initialize SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(0);
// set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
pinMode(dataINPin, INPUT);
pinMode(dataOUTPin, OUTPUT);
pinMode(serialClockPin, OUTPUT);
//!!!Allow self-test to initialize on start-up
delay(500);
}
void loop() {
//!!!assigns integer to store ID value:
long ID = readCommand(WHOAMI);
Serial.println("Device ID: ");
Serial.println(ID, BIN);
Serial.println("\n");
delay(1000);
}
long readCommand(byte Command) {
byte firstByte = 0;
byte secondByte = 0;
byte thirdByte = 0;
byte lastByte = 0;
long result = 0; //result to return
// take the chip select low to select the device:
digitalWrite(slaveSelectPin, LOW);
//!!!SCAT datasheet specifies a 620 microsecond pause to get correct reading
//!!!Page 22 of datasheet
delayMicroseconds(620); // pauses for 620 microseconds
for(int i = 0;i<3;i++) {
//!!! Send dummy command to slave(sensor):
SPI.transfer(Command);
}
//!!!Reads output by using measure command
firstByte = SPI.transfer(Command);
// shift the first byte left, then get the second byte:
firstByte = firstByte << 8;
secondByte = SPI.transfer(Command);
firstByte = firstByte | secondByte;
firstByte = firstByte << 8;
thirdByte = SPI.transfer(Command);
firstByte = firstByte | thirdByte;
firstByte = firstByte << 8;
lastByte = SPI.transfer(Command);
// combine the byte you just got with the previous one:
result = firstByte | lastByte;
// Result is in 32 bit word format with MSB first
// take the chip select high to de-select:
digitalWrite(slaveSelectPin, HIGH);
// return the result:
return(result);
}