Skip to main content
mladen
Associate II
December 12, 2022
Question

How to setup SPI mode 2?

  • December 12, 2022
  • 3 replies
  • 6590 views

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?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
December 13, 2022

> 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
December 13, 2022

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

0693W00000WKsL6QAL.pngsource

hit me up in https://www.linkedin.com/in/javiermuñoz/
waclawek.jan
Super User
December 13, 2022

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

mladen
mladenAuthor
Associate II
December 13, 2022

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