cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Issues - Not Receiving Response on MISO Line After Data Request

dylan
Associate III
Posted on February 07, 2017 at 14:59

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:0690X00000606DzQAI.png

- 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:

0690X00000606GdQAI.png0690X00000606E9QAI.png

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

1 ACCEPTED SOLUTION

Accepted Solutions
dylan
Associate III
Posted on February 08, 2017 at 11:12

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

0690X00000606EJQAY.png

View solution in original post

7 REPLIES 7
S.Ma
Principal
Posted on February 07, 2017 at 16:33

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. 

AvaTar
Lead
Posted on February 07, 2017 at 17:31

Did you check the /CS line ?

It is not visible in your analyzer snapshot.

dylan
Associate III
Posted on February 07, 2017 at 16:57

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.

Posted on February 07, 2017 at 18:06

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.

Posted on February 07, 2017 at 18:15

Do you measure those waveforms directly at the MEMS's pins?

JW

Posted on February 07, 2017 at 19:00

Hi,

Yes, probed on both the uC and the MEMS side. Same result at both ends.

Thanks,

Dylan

dylan
Associate III
Posted on February 08, 2017 at 11:12

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

0690X00000606EJQAY.png