stm32之SPI随笔1

SPI  广泛用于 ADC LCD MCU    全双工  
{
全双工:在A给B发信号的同时,B也可以给A发信号
半双工:指A能发信号给B,B也能发信号给A,但这两个过程不能同时进行 
单工:指A只能发信号,而B只能接收信号,通信是单向的
}
SPI 物理层特点 :一主机多从机   通过ss片选线确定从机,低电平有效,并作为起始信号。高电平结束信号。

上升沿触发,下降沿采样


spi模式        CPOL    CPHA       空闲SCK时钟   采样时刻
    0                0            0            低电平              奇数边沿
    1                0            1            低电平              偶数边沿
    2               1             0            高电平              奇数边沿
    3               1             1           高电平              偶数边沿
    
    
SPI特性:
STM32 SPI外设可用作主机或从机,支持最高的SCLK时钟频率为f/2,数据帧可为8位或16位。时钟是由主机控制

flash存储特性:
1 在写入数据之前必须先擦除置1
2 写入数据时只能将数据位1改为0
3 擦出须以最小单位(一个扇区一般4096byte)
SPI架构:
spi
 BR 位控制时钟频率,作为主机有效
 DR    数据寄存器
 CR 主从,单双向,spi模式
 SR    spi工作状态。
 发送标志位TXE,接收标志位RXE    BSY硬件标志位

 

SPI 库函数
SPI_Init();//结构体初始化
SPI_Cmd();//使能

typedef struct
{
  uint16_t SPI_Direction;           /*!< Specifies the SPI unidirectional or bidirectional data mode.
                                         This parameter can be a value of @ref SPI_data_direction */

  uint16_t SPI_Mode;                /*!< Specifies the SPI operating mode.
                                         This parameter can be a value of @ref SPI_mode */

  uint16_t SPI_DataSize;            /*!< Specifies the SPI data size.
                                         This parameter can be a value of @ref SPI_data_size */

  uint16_t SPI_CPOL;                /*!< Specifies the serial clock steady state.
                                         This parameter can be a value of @ref SPI_Clock_Polarity */

  uint16_t SPI_CPHA;                /*!< Specifies the clock active edge for the bit capture.
                                         This parameter can be a value of @ref SPI_Clock_Phase */

  uint16_t SPI_NSS;                 /*!< Specifies whether the NSS signal is managed by
                                         hardware (NSS pin) or by software using the SSI bit.
                                         This parameter can be a value of @ref SPI_Slave_Select_management */
 
  uint16_t SPI_BaudRatePrescaler;   /*!< Specifies the Baud Rate prescaler value which will be
                                         used to configure the transmit and receive SCK clock.
                                         This parameter can be a value of @ref SPI_BaudRate_Prescaler.
                                         @note The communication clock is derived from the master
                                               clock. The slave clock does not need to be set. */

  uint16_t SPI_FirstBit;            /*!< Specifies whether data transfers start from MSB or LSB bit.
                                         This parameter can be a value of @ref SPI_MSB_LSB_transmission */

  uint16_t SPI_CRCPolynomial;       /*!< Specifies the polynomial used for the CRC calculation. */
}SPI_InitTypeDef;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值