Measure via SPI / accelerometer-sensor

Hello there,

I´m very desperated. I try to read the angle-data from a Murata Sensor called SCA830-D05.
Here you can see the data-sheet:
http://www.murata.com/products/sensor/catalog/pdf/sca8x0_21x0_3100_product_family_specification_82_694_00g.pdf
--> @ page 22 you can see the discription of the frames.

afterwards my code:

// include the library code:
#include <SPI.h>
#include <DSPI.h>
#include <SoftSPI.h>
#include <math.h>

// initialize the library with the numbers of the interface pins


//SPI Pins
#define slaveSelect 10    // Chip Select Pin
#define dataOut 11        // MOSI
#define dataIn 12         // MISO
#define spiClock 13       // SCK serial-clock


//----------------------------------------------------------------------
void setup()
{
 
  pinMode(slaveSelect, OUTPUT);
  pinMode(dataOut, OUTPUT);
  pinMode(dataIn, INPUT);
  pinMode(spiClock, OUTPUT);
     
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  
  delay(10);
 
  Serial.begin(9600);
 
}

//----------------------------------------------------------------------
void loop() 
{
  unsigned short int Yaxis;
  float a, alpha;
 
 //START SPI------------------------------------------------------------- 
  digitalWrite(slaveSelect,LOW);
  delay(50);
  SPI.transfer(0x15);  
  Yaxis = Yaxis | SPI.transfer(0x00);  
  digitalWrite(slaveSelect,HIGH);
  Yaxis = Yaxis << 8;  
  digitalWrite(slaveSelect,LOW);
  SPI.transfer(0x10);  
  Yaxis = Yaxis | SPI.transfer(0x00);  
  digitalWrite(slaveSelect,HIGH);
  //END SPI---------------------------------------------------------------
  
  a = (float)Yaxis / 32000.0 *90.0;
  alpha = asin(a);
  
  Serial.print(alpha,DEC);
  Serial.println(" ");
  delay(25); 
   
 }

I checked every signal, serial-clock, CSB, MOSI -everything is fine.
At MISO the output is 3.3 V.
After that I checked a digital-switch supplied by 3.3 V with digital.Read function -->it works...

Why is it impossible to show the code by serial.print on the serial monitor??
Is there a mistake?

I´m very thankful if somebody can help.

Thank you very much, kind regards Micha

#include <SPI.h>
#include <DSPI.h>
#include <SoftSPI.h>

Which are you using? Why are you including the others?

  Serial.print(alpha,DEC);

Since a float has 6 to 7 digits of accuracy, printing 10 digits after the decimal point seems silly. Why are you doing it?

Why is it impossible to show the code by serial.print on the serial monitor??

It''s not.. You have to explain what this means.. And watch your punctuation..

Step 1: print the raw SPI data to serial so you can see just what (if anything) you are getting.
Step 2: break each part of your calculation down into individual steps and print out each step to ensure you're getting the right values as you progress through the calculations.

Hey guys,

thank you for your support.
The mean problem was the calculation of the value.
First on serial-Monitor the note "nan" was coming.
Now the value printet on the serial-monitor is the same like the value on the scope :slight_smile:

regards Micha