用户工具

站点工具


标准:bus:spi:start

SPI(Serial Peripheral interface)

串行外围设备接口。

常用标准

SPI为De-facto standard,即没有特定的组织来管理定义其规范,这也导致其有很多不同的版本。

对于Basic SPI,Freescale发布了一个标准版本: SPI Block Guide V04.01

版本差异

三个版本,Basic SPI、Dual SPI(DSPI)、Quad SPI(QSPI)。

DSPI和QSPI和Basic SPI的差异为数据线为双向,但其是半双工,即同一时间只能单向传输数据,不能像千兆网口一样,同时双向传输数据。

Basic SPI

Basic SPI的管脚定义如下表:

Name Function
nCS Chip select, a.k.a. slave select (nSS). This is driven low (hence the n) by the master to select a slave. There is a separate chip select line going from the master to each slave.
SCLK Clock. Driven by the master, this provides the clock signal to the slaves to clock data in and out with. The exact polarity and edges that are used depend on the values of CPOL and CPHA.
MOSI Master out, slave in. A.k.a. main out, subnode in. The master drives the line and provides data to the slaves. Only the slave with nCS asserted (low) listens to the data.
MISO Master in, slave out. A.k.a. main in, subnode out. The selected slave can drive this line to send data to the master.

上图为四线的Basic SPI,另有几种变体:

  1. Master没有nCS片选信号,单个Slave的片选直接拉低为常开状态
  2. MOSI和MISO共用一个信号线,通过分时的方法实现输入和输出
  3. Master只用到了nCS SCLK和MOSI/MISO其中一个共三根线,只需接收或发射,单发射如MCU对接SPI的LCD显示屏。

Dual SPI

Dual SPI(DSPI)把Basic SPI两根单向的数据线,变为双向的两根数据线,传输速率翻倍。

Quad SPI

Quad SPI(QSPI)则是四根双向数据线,传输速率为再翻倍。

Transmission Formats

Basic SPI有四种模式,按空闲时时钟电平,以及采样的时钟边缘分。

空闲时时钟电平为0对应CPOL = 0,1对应CPOL = 1。

第一个时钟边缘采样对应CPHA = 0,第二个则对应CPHA = 1。

不是每个芯片都支持这四种模式,一般均支持0和3,Master和Slave设备需要设定成同一个模式。

另Master设备可以在一个总线上和不同模式的slave设备通讯,只需要保证通讯时其他slave设备是inactive状态。

列表和示意图如下:

SPI Mode Clock Polarity (CPOL) Clock Phase (CPHA) Which Clock Edge Is Used To Sample/Shift?
0 0 0 Data sampled on rising edge and shifted out on falling edge.
1 0 1 Data sampled on falling edge and shifted out on rising edge.
2 1 0 Data sampled on falling edge and shifted out on rising edge.
3 1 1 Data sampled on rising edge and shifted out on falling edge.

总线拓扑

两种拓扑,分别如下。

Multidrop configuration

一个Master,一个或多个Slave设备,master有单独的片选信号(或者通过GPIO扩展芯片扩展)对应相应的Slave设备,示意图如下:

Daisy chain configuration

即菊花链模式,Master设备只有一个片选信号连接多个Slave设备,而Slave的MISO作为下一个Slave设备的MOSI,数据在多个Slave设备之间传递。如下图所示,注意这个不是所有的Slave都支持此功能。

设计要求

  1. Master和Slave需要支持同一种版本的SPI(Baisc Dual or Quad SPI),对于Basic SPI还需看支持同一种SPI Mode。
  2. SPI的时钟频率不同的芯片差异很大,从几十kHz到几百MHz,Master和Slave只能按照两者中较低的频率进行通讯。
  3. SPI的时钟如果大于50MHz,PCB需要按照高速线要求布线,如做阻抗控制和阻抗匹配,考虑串扰和干扰等。
  4. SPI为非标准协议, 一定要确认芯片Datasheet中的具体要求。
  5. SPI的信号电平一般有1.8V和3.3V两种,Master和Slave信号电平需要一致,不一致的需要做电平转换,如果频率高于1M,需要用专用的转换芯片,详见TI文档 ti_voltage_translation_buying_guide

参考文献

评论

请输入您的评论. 可以使用维基语法:
E F O L T
 
标准/bus/spi/start.txt · 最后更改: 2025/03/23 17:59 由 hwwiki