# define spiPortOfEEPROM
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: block initialization EEPROM
Entered: no
Output: no
Return back to value: no
Note: prepared without
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void InitEEPROM (void)
{
//MX25L - CS, initialization choose PA4
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_15;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_100MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);
//initialize the corresponding spi
SPI_Configuration (spiPortOfEEPROM);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the Function Name: SPI_Configuration
* Description: SPI module initialization, [including related IO port initialization]
* Input: None
* the Output: None
* Return: None
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void SPI_Configuration (unsigned char port)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
The switch (port)
{
Case 1:
//start SPI1 clock
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);//can make GPIOB, GPIOC clock
RCC_APB2PeriphClockCmd (RCC_APB2Periph_SPI1, ENABLE);//can make SPI2 clock
GPIO_PinAFConfig (GPIOA, GPIO_PinSource5 GPIO_AF_SPI1);//PA5 reuse for SPI1
GPIO_PinAFConfig (GPIOA, GPIO_PinSource6 GPIO_AF_SPI1);//PA6 reuse for SPI1
GPIO_PinAFConfig (GPIOA, GPIO_PinSource7 GPIO_AF_SPI1);//PA7 reuse for SPI1
//////here is SPI related GPIO initialization//////
//Configure SPI1 pins: SCK, MISO and MOSI
//GPIOA5 ~ 7 initialization setting
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;//PA5 ~ 7 multiplexing function output
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_100MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;//pull
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);//initialize
//Configure PA4 pin: MX25L_CS pin
//GPIO_InitStructure. GPIO_Pin=GPIO_Pin_12;//PA4
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_4;//PA4
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_OUT;//output
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_100MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;//pull
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);//initialize
SPI_InitStructure. SPI_Direction=SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure. SPI_Mode=SPI_Mode_Master;
SPI_InitStructure. SPI_DataSize=SPI_DataSize_8b;
SPI_InitStructure. SPI_CPOL=SPI_CPOL_High;
SPI_InitStructure. SPI_CPHA=SPI_CPHA_2Edge;
SPI_InitStructure. SPI_NSS=SPI_NSS_Soft;
SPI_InitStructure. SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_256;
SPI_InitStructure. SPI_FirstBit=SPI_FirstBit_MSB;
SPI_InitStructure. SPI_CRCPolynomial=7;
SPI_Init (SPI1, & amp; SPI_InitStructure);
SPI_Cmd (SPI1, ENABLE);
SPI_ReadWriteByte (1, 0 XFF);//start transmission
break;
Case 2:
//start SPI2 clock
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOB, ENABLE);//can make GPIOB clock
RCC_APB1PeriphClockCmd (RCC_APB1Periph_SPI2, ENABLE);//can make SPI2 clock
GPIO_PinAFConfig (GPIOB, GPIO_PinSource13 GPIO_AF_SPI2);//PB13 reuse for SPI2
GPIO_PinAFConfig (GPIOB, GPIO_PinSource14 GPIO_AF_SPI2);//PC2 reuse for SPI2
GPIO_PinAFConfig (GPIOB, GPIO_PinSource15 GPIO_AF_SPI2);//PC3 reuse for SPI2
//////here is SPI related GPIO initialization//////
//Configure SPI2 pins: SCK, MISO and MOSI
//GPIOB13 ~ 15 initialization setting
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;//PB13 ~ 15 multiplexing function output
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_100MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;//pull
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);//initialize
//Configure PB12 pin: SD_CS pin
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_12;//PB12
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_OUT;//output
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_100MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;//pull
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);//initialize
SPI_InitStructure. SPI_Direction=SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure. SPI_Mode=SPI_Mode_Master;
SPI_InitStructure. SPI_DataSize=SPI_DataSize_8b;
SPI_InitStructure. SPI_CPOL=SPI_CPOL_High;
SPI_InitStructure. SPI_CPHA=SPI_CPHA_2Edge;
SPI_InitStructure. SPI_NSS=SPI_NSS_Soft;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull