SPI协议Slave与Master一般而言提供clock的一方称为master。如下图7-1中的SCLK方向可知Processor为master而Peripheral为slave。SPI设备接口SPI uses four main signals:Master Out Slave In (MOSI)Master In Slave Out (MISO)Serial CLocK (SCLK or SCK) and Chip Select (CS) for the peripheral.Some processors have a dedicated chip select for SPI interfacing called Slave Select (SS).SPI传输SPI使用移位寄存器方式传输示意图形成一个循环圈任何时刻对于一个SPI设备而言都有移位输入和移位输出。如果想只读或者只写那么在读的时候需要发送一个dummy byte从而产生时钟在写的时候简单的忽略读到的数据就可以了。giga Nor flashAll commands, addresses and data are shifted in and out of the device, beginning with the most significant bit on thefirst rising edge of SCLK after CS# is driven low. Then, the one-byte command code must be shifted in to the device, mostsignificant bit first on SI, each bit being latched on the rising edges of SCLK.See Table2, every command sequence starts with a one-byte command code. Depending on the command, thismight be followed by address bytes, or by data bytes, or by both or none. CS# must be driven high after the last bit of thecommand sequence has been shifted in. For the command of Read, Fast Read, Read Status Register or Release fromDeep Power-Down, and Read Device ID, the shifted-in command sequence is followed by a />1、SPI Flash 即SPI Nor Flash是Nor Flash的一种2、NOR Flash根据数据传输的位数可以分为并行ParallelNOR Flash和串行SPINOR Flash3、SPI Nor Flash每次传输一个bit位的数据parallel Nor Flash每次传输多个bit位的数据有x8和x16bit两种4、SPI Nor Flash比parallel便宜接口简单点但速度慢。SPI传输的四种方式根据时钟极性和时钟相位的不同共有四种时钟极性和相位分别指时钟极性(CPOL-Clock Polarity)空闲时的极性高polarity high或者低polarity low。时钟相位(CPHA-CLock Phase)在上升沿还是下降沿采样数据。四种模式用图说明如下将四种模式的采样时刻Sampling edge和数据变化时刻Toggling edge截取出来在逻辑分析仪上面的配置有可能稍有些不一样:上图是一个虚拟逻辑分析仪软件上的SPI配置截图除了通道选择和字长度配置外它还有其他四个设置MOSI Samples:如果是方式0和3那么这里是上升沿方式1和2应该配置为下降沿。看前面的方式说明图。MISO Samples:SO和SI在同一种方式下采样边缘一般是一样的因此同上。Use Enable:是否使用CS Pin脚。Enable Active:这个是CS有效时候的电平。示例SPI寄存器配置在某一个SoC上时钟极性和时钟相位的配置寄存器时钟极性配置查看前面的4种模式图可以知道模式0和模式1应该是配置为0另外两种配置为1时钟相位配置查看前面的4种模式图可以知道模式1和模式3应该是配置为1【第二个edge】另外两种配置为0一般除了方式设置外还需要对时钟速度配置这个配置根据不同的SoC跟踪时钟如何分频过来就可以得出。并且需要注意不要超过Spi-Slave设备的最大速度。SPI reset配置SPI Nor Flash这里用EN25Q128为例简略说明一下SPI的配置。这里使用模式0标准SPI模式只用一根DO线。SPI-NorFlash的接线