1

I'm trying to communicate with an MPU6500 sensor via SPI as I need the fastest possible update rate. I have trouble finding an easy to understand sample code, or perhaps a lightweight library how to configure and initialize the sensor and read gyro / accelerometer data via SPI.

So far I started adapting the code and info found at https://playground.arduino.cc/Main/MPU-6050 thought it would be fairly easy to use SPI instead of I2C "Wire", and adapt the configuration and registers based on the datasheet, but I realized there's too many possible pitfalls.

Any recommendations?

5
  • What library you already found? And what part of the sample code you have questions about? Feb 28, 2018 at 14:56
  • @MichelKeijzers added info.
    – Z4-
    Feb 28, 2018 at 16:48
  • I retracted my close flag, I never tried this sensor, normally components are either for SPI or I2C (or another communication means), but not supporting both, so I am surprised you can even change from I2C to SPI. Feb 28, 2018 at 17:22
  • Read the data sheet and SPI protocol is quite easy to implement!
    – MaNyYaCk
    Mar 1, 2018 at 9:51
  • Thanks Michel, yes it does definitely support both.
    – Z4-
    Mar 1, 2018 at 9:54

1 Answer 1

1

For anyone who has not yet figured this out, its very simple.

Basically, for SPI communication with the sensor MPU 6500, its a bit different from what I2C has to offer.

In I2C, basically you will find the data packet is as follows:

(7 bit Slave Address + Read/Write Bit), but in SPI it is as follows:

(Read/Write Bit + 7 Bit Register Address), notice we dont even need the slave address in SPI as the Chip Select is connected from processor(Master) to Sensor(Slave).

So for SPI, lets say you want to write a value 64 to register 0x6B, then: Transmission_data[2]; Transmission_data[0] = 0x6B; Transmission_data[1] = 64;

Lets say you want to read a value from register 0x43, which is GYRO_X_High Byte value, then, Transmission_data[1]; Transmission_data[0] = 0x43 | 0x80; // you need to or it with 0x80(decimal = 128)

Thanks...Hope this helps someone in need of help for SPI as I struggled too in finding this information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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