SPI question with MPU9250

Hi everyone,

I am trying to get SPI working in combination with an MPU9250 gyroscope. I get it configured, and can write fine to the MPU to get it responding with the right information. The issue is however the reading.

For instance, with the command:

   var writeBytes  = new byte[] { 0xC1, 0, 0 };
   var readBuffer = new byte[3];
   _spiDevice.TransferSequential(writeBytes, readBuffer);

I sent the read request for a temperature-reading (value 193) and ask for two response bytes (the two 0’s). I see with the Logic analyzer the following response:

  0xC1/0x00 0x00/0x07 0x00/0x89 0x00/0xFF 0x00/0xFF 0x00/0xFF

So, I would assume my read buffer would contains the value 0x00, 0x07 and 0x89. However, I receive in the end the values: 0x89 0xff 0xff

I am not really sure how I should interpret this, and how I can receive also the 0x07 value. I have already tried to sent multiple Transfers, but then the response gets empty as the chip select goes down, and the chip doesn’t know what to return anymore. Has anyone some insights how I should use this SPI-commands to retrieve all the results?

For clarification also an image from logic:

Have you tried the TransferFullDuplex here? Replace _spiDevice.TransferSequential(writeBytes, readBuffer); with _spiDevice.TransferFullDuplex(writeBytes, readBuffer);

I don’t have a MPU9250 on hand at the moment, so I can’t test your code.

Thanks for your response, had not enough time in between but I finally tested it yesterday.

I got the whole solution working now, by changing indeed to TransferFullDuplex. However, in addition I had to remove the CS-line from the SpiDevice-class (put it to None), and manage it manually. When I applied that change, I finally started receiving data. I haven’t found out yet why this changes it, but I can finally continue by getting the MPU9250 work with my board.

Maybe you are using the wrong SPI mode. So instead of pulling CS low, it gets pulled high or vice versa.

Anyway, happy to hear it works now!