#include "spi.h"



void SPI1_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	SPI_InitTypeDef SPI_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//ʹSPI1
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//ʹGPIOA

	GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//ٶ50MHz
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;	 //
	GPIO_Init(GPIOA, &GPIO_InitStructure); //ʼGPIOA
	GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_7);

	SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;//ֻģʽ
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//SPIģʽģʽ
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//SPIݴС8λ֡ṹ
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//ͬʱӿʱSCLKλߵƽ
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//ͬʱӿյڶʱز
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//NSSźӲ
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//ԤƵֵԤƵֵΪ4
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//ݴλ
	SPI_InitStructure.SPI_CRCPolynomial = 7;//CRCֵĶʽ
	SPI_Init(SPI1,&SPI_InitStructure);//ʼSPI
	SPI_Cmd(SPI1, ENABLE);//ʹSPI
}






