cancel
Showing results for 
Search instead for 
Did you mean: 

MPU9250 SPI - Only receive 0xFF

San Der
Associate II
Posted on April 14, 2018 at 17:27

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
7 REPLIES 7
martinj3456
Associate III
Posted on April 16, 2018 at 07:07

Have you solved your issue yet?

Recently, I've interfaced MPU9250 with STM32L476 using LL SPI libraries instead of HAL.

I've ported this Arduino Library to my projects. Worked well for me. You may also try.

https://github.com/brianc118/MPU9250

 

Initialization codes are little lengthy. The SPI clock might be needed less than 8MHz.

Thank you.

Posted on April 16, 2018 at 11:08

I still have the issue. Is using LL SPI libraries much more difficult? Thanks

Posted on April 16, 2018 at 18:12

LL SPI libraries are easy to use. I'm using for L4. Not sureLL librariesfor F7 are available or not.

You can use your mpu_write_registercommand and follow the initialization command provided in Arduino GitHub.

Could it possible the chip is enabled for I2C instead of SPI ?

Most of online examples are for I2C.

Thanks

Posted on April 18, 2018 at 14:42

I went with I2C for now as that worked. Might be something with the breakout board and SPI.

Thanks
Július Kovács
Associate II
Posted on April 19, 2018 at 10:36

Hello,

I think there is a problem in function

mpu_read_byte. 
You want read two bytes, but the supplied buffer is only one byte long.

In addition, it is often a problem with the unreaded value in the receiving buffer.

Try clear previosly received bytes before calling

HAL_SPI_TransmitReceive

function.
Geoffrey Furman
Associate II
Posted on April 19, 2018 at 14:25

I cannot comment on your code but your MISO signal is not correct. All logic levels should be 3.3V. There must be a another signal driving the MISO line that should not be there. Either that or something is happening to the 3.3V power supply on the 9250. I would worry about code until that is fixed.

San Der
Associate II
Posted on April 20, 2018 at 00:14

Thanks for the answers!

I acquired a new MPU9250 breakout board earlier today and tested again with SPI. This time I got it to work! Seems like there was something wrong with the old breakout board after all.

AlsoI had to change the mpu_read_byte function as you stated

Made it a little more general also to be able to read multiple registers from the MPU.

So now it's all good and working correctly with SPI.

Thanks again for the help!

HAL_StatusTypeDef mpu_read_bytes(uint8_t rd_reg, uint8_t *rd_data, uint16_t length){HAL_StatusTypeDef status;uint8_t data_rd_bit = rd_reg | 0x80;HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);if((status = HAL_SPI_Transmit(&hspi1, &data_rd_bit, 1, HAL_MAX_DELAY)) != HAL_OK) {return status;}status = HAL_SPI_Receive(&hspi1, rd_data, length, HAL_MAX_DELAY);HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);return status;}�?�?�?�?�?�?�?�?�?�?�?�?�?�?