MLX 90609

Hi, I am trying to interface the MLX rate gyro with an Arduino board. I am having trouble using the SPI because I don't know the correct sequence of bits to send to the microcontroller to get a reading.

The following links may be helpful to someone who knows what they are doing:

RobotShop | Robot Store | Robots | Robot Parts | Robot Kits | Robot Toys...-datasheet.pdf

Maybe this will be more clear. On page 14 of the datasheet it says:
-Step 1 (put ADC to the active mode if it wasn't)

-Use SPI to send ADCC instruction (MOSI):
1 0 0 1 x 1 0 0 x x x x x x x x x x x x x x x x

-And check 15th bit of the answer (MISO):
0 x x x x x x x x x x x x x x x
If 15th bit is zero, the instruction is accepted.
Before to go to the Step 2 provide a delay > 115 µs or wait till the EOC bit is set.

However, on the Arduino learning web site of SPI EEPROM it says:

The SPI control register (SPCR) has 8 bits, each of which control a particular SPI setting.

SPCR
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| SPIE | SPE | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 |

SPIE - Enables the SPI interrupt when 1
SPE - Enables the SPI when 1
DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0
MSTR - Sets the Arduino in master mode when 1, slave mode when 0
CPOL - Sets the data clock to be idle when high if set to 1, idle when low if set to 0
CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0
SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)

So, if I send the bit sequence that the data sheet tells me to, the SPE will be set to 0 which will turn off the SPI.

I send a 1 for the SPE and MSTR and the rest 0's. Then the Arduino sends thing back but, if i'm not sending the correct instructions why does this work?

Here is the code i've been using so far:
#define SCLK 13 // LED connected to digital pin 13
#define SS 10
#define MOSI 11
#define MISO 12

void setup()
{
pinMode(SCLK, OUTPUT); // sets the digital pin as output
pinMode(SS, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
digitalWrite(SS, LOW); // disables the device
byte clr;
Serial.begin(9600); // begin serial comm

SPCR = (1<<SPE)|(1<<MSTR); // clear SPDR & SPCR
clr = SPSR;
clr = SPDR;
delay(250);
Serial.println("Setup Done . . . ");
}

int i = 0;

void loop()
{
digitalWrite(SS, LOW); // activates device
spi_transfer (i);
delay(250);
spi_transfer(0x00); // data byte
digitalWrite(SS,HIGH);
i++;

Serial.println(i);
Serial.println(SPDR);
}

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission
{
};
return SPDR; // return the received byte
}

Hi,
looks like you got mixed up with initializing the SPI on the Arduino and the data that is to be send to the external device.

Everything you stated about the SPI control-register is done in the setup()-code and has nothing to do with the data to be send to your device.

The device specific data

-Use SPI to send ADCC instruction (MOSI):
1 0 0 1 x 1 0 0 x x x x x x x x x x x x x x x x

-And check 15th bit of the answer (MISO):
0 x x x x x x x x x x x x x x x
If 15th bit is zero, the instruction is accepted.

are the bytes that get send with the spi_transfer() method to the device.

Since you have to send 16bit=2bytes for each command your loop-function might look something like this

digitalWrite(SS, LOW); // activates device
//create the ADCC command
byte adccHighByte=B10010110;
byte adccLowByte=B00000000;
spi_transfer (adccHighByte);
spi_transfer (adccLowByte);
digitalWrite(SS,HIGH);//deactivates device

All I can spot right now since I don't know your device and the link to the datasheet doesn't work.
Eberhard