2017-02-07 05:59 AM
Hi All,
I am new to the STM32 platform and as such I am playing around with sensors to gain some experience. I am using Atollic Lite and CubeMX to ease the learning curve.
I am having a problem communicating over SPI with an MPU-9250 IMU - All I want to do right now is read the WHO_AM_I register and as such I am using the HAL_SPI_Transmit(), HAL_SPI_Receive() and HAL_SPI_TransmitReceive() functions.
Here is a screen grab from my logic analyser:
- The first clock burst is a
HAL_SPI_Transmit() to write data.
- The second and third clock bursts is a HAL_SPI_Transmit() and HAL_SPI_Receive() to read a registers data.
- The fourth and fifth clock bursts are a HAL_SPI_TransmitReceive() to read the same register data as in the previous burst.
As you can see, there is no response on the MISO line when data requests are made. This is my problem and for the life of me I cannot find the issue. I have a feeling is is a configuration issue that I can't see because of lack of experience.
Here are extracts from the MPU-9250 data sheets:
Attached below are the contents of my main.c file containing the initialization of the clock, the GPIO's and SPI.
If any one can see my mistake, help would be greatly appreciated! If you need more info, please don't hesitate to ask.
Kind regards,
Dylan
Solved! Go to Solution.
2017-02-08 02:12 AM
Hi All,
I have solved the problem. The MPU-9250 is by default setup to be an I2C device and so in order to communicate over SPI you have to disable I2C by writing a bit to one of the registers. I was doing this but was then requesting data without letting the device breathe. The cure has been to disengage the CS line after writing the bit to disable I2C and then to engage again and request data.
Thanks for every ones help, I much appreciate it!
Kind regards,
Dylan
2017-02-07 07:33 AM
Some MEMs default after power reset in SPI 3 wire mode. To activate the 4 wire mode, the MCU should set the 4 wire mode by setting the proper bit in the sensor control register.
2017-02-07 08:31 AM
Did you check the /CS line ?
It is not visible in your analyzer snapshot.
2017-02-07 08:57 AM
Hi,
Thanks for the response!
From what I understand, the MPU-9250 doesn't support the 3 wire interface, only the 4 wire. The data sheet does say that one has to disable the I2C interface after start up. That is the first bit that I write in the code. Maybe I need to do a full device reset before trying to do any communication - will give it a go and report back.
2017-02-07 10:06 AM
Yes, It did check it. It goes active low before transmission amd then inactive high at the end. You cam see it in my original post - it is the 4th channel.
2017-02-07 10:15 AM
Do you measure those waveforms directly at the MEMS's pins?
JW
2017-02-07 11:00 AM
Hi,
Yes, probed on both the uC and the MEMS side. Same result at both ends.
Thanks,
Dylan
2017-02-08 02:12 AM
Hi All,
I have solved the problem. The MPU-9250 is by default setup to be an I2C device and so in order to communicate over SPI you have to disable I2C by writing a bit to one of the registers. I was doing this but was then requesting data without letting the device breathe. The cure has been to disengage the CS line after writing the bit to disable I2C and then to engage again and request data.
Thanks for every ones help, I much appreciate it!
Kind regards,
Dylan