Skip to main content
Associate II
August 16, 2025
Solved

What is the SPI mode of the gyroscope sensor I3G4250D?

  • August 16, 2025
  • 5 replies
  • 1778 views

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!

 

Best answer by TDK

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.

5 replies

TDK
Super User
August 16, 2025

> 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""."
Associate II
August 17, 2025

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

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

 

TDK
Super User
August 17, 2025

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""."
Associate II
August 18, 2025

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

 

Associate II
August 18, 2025

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
TDKBest answer
Super User
August 19, 2025

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""."
Associate II
August 21, 2025

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

-->Wowww. It works. Thank you very much. Could you explain why?

TDK
Super User
August 21, 2025

The CLK pin is not driven until the peripheral is enabled. On the first transaction, it's low when you set CS low, which messes up the first transfer. Doing a dummy transfer enables the peripheral. See my first reply.

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

Thank you very much again : ))