I'm trying (for sport...) to use an MPU-9250 in SPI mode as it should be faster, and wasn't able to talk to the embedded magnetometer in my code.

I've gone through the documentation (RM-MPU-9250A-00 v1.4) which is a bit spartan on that subject but gives the rough idea, it should work by enabling the built-in I2C master feature and using "proxy" I2C registers; I've tried to "do as it says" to communicate with the magnetometer; I'm querying the magnetometer identification register, and I only see 0x00 in there.

I searched in nature, and couldn't find an example of F/LOSS software using an external sensor plugged on the MPU.

Perhaps I've done something wrong but I can't see it, so here's a bottle in the ocean :)

  • Why would you need to enable I2C master if you want to use SPI? That just seems wrong, like the author of the doc was having a bad day. Can you search around and see if there is any other evidence that this is the right thing to do, – Code Gorilla Mar 6 '17 at 13:12
  • The IMU chip can act as an I2C master to talk to downstream I2C devices... – cJ Zougloub Mar 6 '17 at 16:49

It turns out that my mistake was in the SPI communication code, but nevertheless here is some info because it's not very obvious.

I went over the top and:

  • Review the electrical interface to see whether by any chance, my chip was badly hooked-up. Everything was fine.
  • Enabled register read-back and saw that... owww, it was bad.
  • Reviewing PS-MPU-9250A-01 § 7.5 SPI Interface I saw that I had made a stupid copy&paste error in my code... when copying my read code over to the write I forgot to adjust the MSB of the first spi byte.


  • I2C_MST_P_NSR=1 seems important or we get zeros
  • basic config in there, currently using the I2C proxy to read the magnetometer, and I don't like having a sleep to wait for I2C transfers to happen or not, but this is a WIP and the code won't go anywhere.
  • 1
    accept your onwn answer – esoterik Jan 30 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.