51單片機模擬SPI時序操做ds1302(軟件模擬)經過時序圖模擬時序,經過位於,移位讀出(寫入)數據,注意高低位函數
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 */8或16位
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 whch 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 masterclock. 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;
2.1:先明白Pixy的串行協議:SPI通訊,在Data Out Port選項中設置:ui
一個數據16位,7個數據,共14字節的數據。
01 00 9B 00 7B 00 A4 00 23 00 55 AA 3A 01 01 00 EE 00 1F 00 1C 00 10 00 55 AA 55 AA
DC 01 01 00 9B 00 7E 00 A5 00 1D 00 55 AA 39 01 01 00 EE 00 20 00 1D 00 0D 00 55 AA
9A 00 7E 00 A5 00 1F 00 55 AA 36 01 01 00 EE 00 1E 00 1C 00 0D 00 55 AA 55 AA E4 01
A2 00 1F 00 55 AA 37 01 01 00 EE 00 1F 00 1C 00 0D 00 55 AA 55 AA D9 01 01 00 9B 00
這幾串數據浪費了我4天時間,真坑。注意SPI與串口讀出的數據開始標誌數據不一樣,
學會用上位機配置好pixy。使用spi協議讀出數據發給串口:
2.4:處理數據:
接下來用讀到的pixy的數據就作你想作的事了。spa
代碼分享:3d
連接:https://pan.baidu.com/s/1tZpToGphMbimu6dnAQ2V_Q
提取碼:ms0q
指針