cancel
Showing results for 
Search instead for 
Did you mean: 

What is the SPI mode of the gyroscope sensor I3G4250D?

duoc_ngo261
Associate II

duoc_ngo261_0-1755342937872.png

I use the KIT STM32F411 Discovery

When I choose:

SPI CPOL: Low

SPI CPHA: 1 Edge

It works

 

But when I choose:

SPI CPOL: High

SPI CPHA: 2 Edge

It does not work

 

Could you explain why? Thank you!

 

7 REPLIES 7
TDK
Super User

> SPI CPOL: High

> SPI CPHA: 2 Edge

These are the correct settings. If it doesn't work, there's probably a bug in your code.

Ensure SPI peripheral is active before you assert CS. Send a dummy transfer without CS active in order to ensure this.

If you feel a post has answered your question, please click "Accept as Solution".
duoc_ngo261
Associate II

This is my main.c file. It's short

Could you help me review a little bit? Thank you very much

 

What about your program isn't working?

What does L3GD20_Read_WHOAMI return?

> hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
> hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

These are incorrect, as explained above.

If you feel a post has answered your question, please click "Accept as Solution".

I recorded my screen and send you my project in the attachment.

It works when:

 > hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
> hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

It does not work when:

 > hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
> hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;

I still don't know why : ((

Thank you very much !!!

 

If you can't clearly explain what isn't working here, I'm afraid I won't be able to help. I'm not watching a 4.5 minute video to try and find out. You didn't answer my question about L3GD20_Read_WHOAMI.

If you feel a post has answered your question, please click "Accept as Solution".
duoc_ngo261
Associate II

Hi

What does L3GD20_Read_WHOAMI return?

--> It returns 211

When I use 

 > hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
> hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;

The sensor returns only 1 time (then the sensor data does not change anymore)

Do you know the reason why?

Thank you

duoc_ngo261_0-1755532844611.png

 

 

 

TDK
Super User

Try doing a dummy SPI transfer (with CS high) prior to your first SPI transaction, but after SPI is initialized.

If that doesn't work, please include the code you're using with the fixes from above.

If you feel a post has answered your question, please click "Accept as Solution".