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:
arduino.cc/en/Tutorial/SPIEEPROM
robotshop.ca/content/PDF/sparkfun-mlx90609-chip-datasheet.pdf
Thanks!!
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?
So, I guess my question now is, what is the instruction for the “write” command?
Jonathan, thanks for all your help thus far.
So, now I am able to get the 11 bit number for the angular rate. I plug that into the formula for angular rate given on the Melexis 90609 datasheet:
Voutar(mV) = (25/12)*ADCcode + 400
and this is what I get for the sensor at rest:
Voutar = (25/12)*2014 + 400 = 4595.83 mV
Then I use the equation:
Vout = Bias + Gain*AngularRate
Since the sensor was not rotating at the time when I took this reading, I set AngularRate to zero. I am left with the result:
Vout = Bias = 4.59583 V
However, I am interested in the AngularRate. So, how do I figure out the Gain? Also, what will the units be of the reading? rad/sec? deg/sec?
Thanks again,
varndell
I forgot to drop the LSB before I found the ADCcode. This divides the ADCcode value in half, which gives me a Voutar = 2.497 V. This fits the graph.
Hello Varndell:
Have you considered using the analog output on the MLX90609 instead of the SPI interface, this would be much simpler with the Arduino via its ADC channels.
Otherwise, you will have to study the specifications sheet, it is all there. Your problem is not very clear, are you having problem interpreting the data coming from the MLX90609 or sending commands to it?
Regards,
The Arduino SPI Control Register (SPCR) is a register in the Arduino. This is used to control SPI capabilities of the Arduino only. This is how you set up the SPI Control Register:
// SPCR = 01010000
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/4 rate (fastest)
SPCR = (1<<SPE)|(1<<MSTR);
The instruction you send to the the gyro is independent and may work differently. Notice you are doing it differently when sending a command to the SPI device then when setting up the SPI Control Register on the Arduino:
digitalWrite(SLAVESELECT,LOW);
spi_transfer(WRITE); //write instruction
So, the reason it works is because it is slightly unrelated.
Since you are not using an EEPROM, you need to modify the code somewhat.
You need to start the conversion by sending 1 byte: 148 (10010100 Binary)
Then poll regularly by sending 1 byte: 128 (10000000 Binary) to the Gyro, waiting 115us then reading in 2 bytes.
Glad you got this working and thank you for sharing your findings. Also, the units should be degrees/second.