cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup SPI mode 2?

mladen
Associate II

I'd like to setup SPI mode 2 in my project with cpol=1 and cpha=0. But in SPI setup for cpha options are 1 or 2 edges. Which option do I have to select?

6 REPLIES 6

> But in SPI setup for cpha options are 1 or 2 edges. 

No there isn't. SPI in STM32 is set up using the usual CPOL and CPHA settings. It's just the Cube/HAL lingo, and it's not 1 or 2 edges, it's supposed​ to denote first/second edge, but I don't know which one is which in terms of CPOL/CPHA. Cube is open source so you can easily look it up comparing to RM yourself if you insist on using it.

JW​

Javier1
Principal

As @Community member​ said, "1 edge" reffers to 1st edge

0693W00000WKsL6QAL.pngsource

we dont need to firmware by ourselves, lets talk

Still, what's "1st edge", exactly?

The traditional - and unambiguous - way to describe CPHA selection is "sample, then shift" vs. "shift, then sample".

CubeMX might've also made use of the fact that it's a visual tool, and might've added waveforms to clarify things.

JW

Anywhere else CPHA is setup as 0/1 or high/low. Maybe 0 is 1st edge, and 1 is 2nd edge.

sample on 1st clock edge vs. on 2nd edge of clock.

Quite uncommon, but not wrong. And well explained in the IDE:

0693W00000WKw7cQAD.pnghth

KnarfB

I learnt SPI modes with thesame 1st edge and 2nd edge sintaxis.

we dont need to firmware by ourselves, lets talk