#include "SPI.h"
/*****************************************************************/
void SPIx_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//RCC->APB2ENR|=1<<2; //PORTA时钟使能
//RCC->APB2ENR|=1<<12; //SPI1时钟使能
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE );
//这里只针对SPI口初始化
//GPIOA->CRL&=0X000FFFFF;
//GPIOA->CRL|=0XBBB00000;//PA5.6.7复用
//GPIOA->ODR|=0X7<<5; //PA5.6.7上拉
/* Configure SPI1 pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure I/O for Flash Chip select */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //SPI CS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Deselect the FLASH: Chip Select high */
GPIO_SetBits(GPIOA,GPIO_Pin_2);
//SPI1->CR1|=0<<10;//全双工模式
//SPI1->CR1|=1<<9; //软件nss管理
//SPI1->CR1|=1<<8;
//SPI1->CR1|=1<<2; //SPI主机
//SPI1->CR1|=0<<11;//8bit数据格式
//SPI1->CR1|=1<<1; //空闲模式下SCK为1 CPOL=1
//SPI1->CR1|=1<<0; //数据采样从第二个时间边沿开始,CPHA=1
//SPI1->CR1|=7<<3; //Fsck=Fcpu/256
/*****************************************************************/
void SPIx_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//RCC->APB2ENR|=1<<2; //PORTA时钟使能
//RCC->APB2ENR|=1<<12; //SPI1时钟使能
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE );
//这里只针对SPI口初始化
//GPIOA->CRL&=0X000FFFFF;
//GPIOA->CRL|=0XBBB00000;//PA5.6.7复用
//GPIOA->ODR|=0X7<<5; //PA5.6.7上拉
/* Configure SPI1 pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure I/O for Flash Chip select */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //SPI CS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Deselect the FLASH: Chip Select high */
GPIO_SetBits(GPIOA,GPIO_Pin_2);
//SPI1->CR1|=0<<10;//全双工模式
//SPI1->CR1|=1<<9; //软件nss管理
//SPI1->CR1|=1<<8;
//SPI1->CR1|=1<<2; //SPI主机
//SPI1->CR1|=0<<11;//8bit数据格式
//SPI1->CR1|=1<<1; //空闲模式下SCK为1 CPOL=1
//SPI1->CR1|=1<<0; //数据采样从第二个时间边沿开始,CPHA=1
//SPI1->CR1|=7<<3; //Fsck=Fcpu/256