Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micropython中SPI总线模式配置 #38

Open
Meekdai opened this issue Dec 13, 2023 · 0 comments
Open

micropython中SPI总线模式配置 #38

Meekdai opened this issue Dec 13, 2023 · 0 comments
Labels

Comments

@Meekdai
Copy link
Owner

Meekdai commented Dec 13, 2023

在嵌入式系统中,很多板载芯片都是采用SPI总线进行通信,同一SPI总线上也运行挂载多个相同或者不同型号的芯片。但是要留意不同型号的芯片的SPI通信的时序图,一般会有4种模式。在micropython中,初始化SPI总线时,通过phasepolarity配置即可实现这4种模式。

四种模式

模式 CPHA (phase) CPLO(polarity)
MODE0 0 0
MODE1 1 0
MODE2 0 1
MODE3 1 1

CPHA (phase) 0--第1时钟边缘采样 1--第2时钟边缘采样
CPLO(polarity) 0--空闲时钟低电平 1--空闲时钟高电平

常用芯片模式

芯片 模式
TMC5130 MODE3
TMC5160 MODE3
TMC4671 MODE3
MAX31865 MODE1&MODE3
ADS1220 MODE1
DRV8244 MODE1

示例

  1. 如下示例配置了MODE3,可以与所有支持MODE3的芯片通信。
import pyb
spi = pyb.SPI(1, pyb.SPI.MASTER,prescaler=256,phase=1,polarity=1)

具体还可参考官方文档 https://docs.micropython.org/en/latest/library/pyb.SPI.html

  1. 下图为具体时序示例图
    image2018-11-8 9_41_16
@Meekdai Meekdai added the 硬件 label Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant