Skip to main content
Associate II
Aug 16, 2025 11:19 AM UTC
Solved

What is the SPI mode of the gyroscope sensor I3G4250D?

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!

 

This topic has been closed for replies.
TDK
TDKBest answer
Aug 19, 2025 2:30 PM UTC

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""."

10 replies

TDK
Aug 16, 2025 1:20 PM UTC

> 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
Aug 17, 2025 3:52 PM UTC

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

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

 

TDK
Aug 17, 2025 5:20 PM UTC

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
Aug 18, 2025 9:47 AM UTC

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
Aug 18, 2025 4:01 PM UTC

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
Aug 19, 2025 2:30 PM UTC

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
Aug 21, 2025 4:21 PM UTC

"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
Aug 21, 2025 6:17 PM UTC

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
Aug 23, 2025 2:38 AM UTC

Thank you very much again : ))