Connect to MPU 9250 with SPI (or 6000/6500/3300)

Hello,
I've been trying to connect to MPU 9250 IMU sensor. The 9250 version supports both I2C and SPI. I can successfully connect with I2C and stream data but I cannot figure out how to communicate with it via SPI. I can't even read a single register. I am debugging it with an oscilloscope and the device is not replying at all, while I can see all the communication from the Raspberry pi towards the MPU9250 + clock signal. The datasheet is kinda vague I think regarding how you have to switch between the modes.

Does anybody has experience running SPI on some of those chips (9250/6000/6500/3300). They all have the dual SPI/I2C property, and is willing to share code or any other useful experience regarding the issue.

I am not using Arduino, but raspberry pi, although I plan to try Arduino next. Eventually it's going to be read by another Microcontroller board, but I just wanted to get the initial setup with an easier platform. The raspberry pi that I am using can successfully connect with SPI to other devices.

Thank you,

Looking at the Note under the "Serial Interface" table in section 7.1 of the data sheet, as well as Section 4.1 (the pin out) and Section 7.5 (the SPI interface) - also look at Section 4.14 - it looks as though the device will use SPI mode when pin 22 is used as a \CS\ (active low). Therefore I would use the SPI interface to set the I2C_IF_DIS bit as the first command.
How, I am guessing form the way your question is written that you do not (yet) understand that SPI exchanges values - at the same time that the master sends a value to the slave, the slave is sending a value back to the master. Therefore, looking at Section 7.5, it would seem that you need to exchange 2 (or more) 8 bit values with the first byte being a register address and the 2nd byte being either the value that you are writing to that address or a dummy value. The first value you receive back from the device can be thrown away (I think - I have not read the complete data sheet and I see that it references other documents as well such as the register map) and the 2nd (and subsequent) values will be the values returned from the device.
Susan

Hi Susan,
thank you for the reply. I am familiar with the SPI protocol, I've used it interfacing few devices before and know about the synchronous exchange, etc. I've been trying to debug it with oscilloscope and i can see on the host side everything looks, fine. CE line goes down, clock starts, 1st non-zero byte goes through (register address), 2nd byte is zero since I am reading the device. However at the same time the sensor line (MISO) is not active, it just stays at zero (I also feel it might be high impedance mode, since there's slight interference).

I've read the datasheet and that point about I2C_IF_DIS bit is confusing me. I guess I haven't tried to set that bit first thing. What I've been trying to read the WHOAMI register to confirm things are working. What is confusing me is that the datasheet says you are supposed to turn I2C_IF_DIS on 10-100ms after power-up, but I can't quite figure out how to do the timing. I connect the sensor physically, then I run the program. That takes seconds. I am not aware of a programatical way to power the device up and down, without interfacing with the registers, which I can't do with SPI.

What I've tried is using the I2C interface and then turning on that bit and that indeed immediately resulted in loss of communication. However, then manually switching the wires to SPI did not work again (the SPI was not communicating again).

I thought, that since the CE line is not used in I2C mode (but pulled up to VCC) when the line goes down in the SPI communication the sensor would immediately know it needs to talk SPI so I thought things should be fairly trivial.

I tried to explain in detail what I am doing. I hope someone can spot an error in my flow.

Thank you,
Svet

I will leave it to others who know more about the device and the Arduino/RPI to assist you further.
However my experience with other microcontrollers is that there may be a short on the MISO line (possibly not if the I2C is working) or the microcontroller side is set as an output - again not sure with the RPI but given that this is also the I2C SDA line then it might be.
Susan

Thank you all!
I solved the problem finally. It was very basic mistake. You have to read section 7.5 from the datasheet carefully. It says when reading registers you have to add 0x80 to the address. I wasn't doing that so all my communications were writes, hence no response from the MPU. Also the communication wasn't working when I had the oscilloscope probes attached as well.

hi Svet

I am trying to make SPI work on MPU9250 and but could not able to make it success.
I am using Aardavark board to test. I used TotalPhase control software and the I2C worked for me. I can read the WHOAMI reg correctly.

Can you please let me know what message sequence you gave ?