Read and Write with SPI 8bit , 7bit ?

Hi, i have an imu sensor. It communicates over SPI. I use Mega2560 ,

I want to read one simple register WHO_AM_I register.

/*
on documentation
SPI Operational Features

  1. Data is delivered MSB first and LSB last
  2. Data is latched on the rising edge of SCLK
  3. Data should be transitioned on the falling edge of SCLK
  4. The maximum frequency of SCLK is 1MHz
  5. SPI read and write operations are completed in 16 or more clock cycles (two or more bytes). The
    first byte contains the SPI Address, and the following byte(s) contain(s) the SPI data. The first
    bit of the first byte contains the Read/Write bit and indicates the Read (1) or Write (0) operation.
    The following 7 bits contain the Register Address. In cases of multiple-byte Read/Writes, data is
    two or more bytes:

SPI Address format
MSB LSB
R/W A6 A5 A4 A3 A2 A1 A0

SPI Data format
MSB LSB
D7 D6 D5 D4 D3 D2 D1 D0
*/

On Registermap WHO_AM_I
Hex Add / Dec Add / Register Name / Serial I/F / bit7 / bit 6 ..... bit 0
75 / 117 / WHO_AM_I / R / WHOAMI[7:0]


Pin Assigments
51 > SDI
52 > SCLK
50 > SDO/ADO
53 > CS

#include <SPI.h> //add arduino SPI library;
//list of all registers binary addresses;
byte WHO_AM_I           = 0B01110101;


byte Read  = 0B10000000;
byte Write = 0B00000000;

//chip select pin on arduino;
const int CS = 53;
/*
SPI.h sets these for us in arduino
const int SDI = 11;
const int SDO = 12;
const int SCL = 13;
*/

void setup() {
  Serial.begin(57600);
  //start the SPI library;
  SPI.begin();
  //initalize the chip select pins;
  pinMode(CS, OUTPUT);

}

void loop() {

byte rValue = ReadRegister(WHO_AM_I);

Serial.print(Read | WHO_AM_I,BIN);
Serial.print(" > Value: ");
Serial.println(rValue);
delay(1000);

}

byte ReadRegister(byte Address){
  byte result = 0;
  digitalWrite(CS, LOW); 
  SPI.transfer(Read | Address);
  result = SPI.transfer(0x00);
  digitalWrite(CS, HIGH);
return(result);  
}

void WriteRegister(byte Address, byte Value){
  digitalWrite(CS, LOW);
  SPI.transfer(Write | Address);
  SPI.transfer(Value);
  digitalWrite(CS, HIGH);
}

Could anyone help ?

Help with what? Looks like you have ok code to me. Does it not work?

sensor is mpu 9250 imu.

With these codes it's just returned 0 not device id

No error code returned.

Do you have a link to a datasheet?

Does the part with default SPI Mode 0 (SCK normally low, data available on the correct edges),

and at the default 4 MHz SCK speed?

Here the datasheet and registermap for 9250

PS-MPU-9250A-01.pdf (655 KB)

RM-MPU-9250A-00.pdf (508 KB)

From the data sheet it looks like you will need a SPI.setDataMode(SPI_MODE3) just after the SPI.begin in your sketch.