30 SPI_InitTypeDef SPI_InitStructure;
31 GPIO_InitTypeDef GPIO_InitStructure;
35 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
36 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
40 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
51 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
52 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
53 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
56 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
69 ERRA(
"SPI(%d) is not allowed", spi);
73 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
74 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
75 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
76 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
77 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
78 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
79 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
80 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
81 SPI_InitStructure.SPI_CRCPolynomial = 7;
82 SPI_Init(SPIx, &SPI_InitStructure);
83 SPI_Cmd(SPIx, ENABLE);
110 ERRA(
"SPI(%d) is not allowed", spi);
115 GPIO_ResetBits(GPIOx, GPIO_Pin);
117 GPIO_SetBits(GPIOx, GPIO_Pin);
141 ERRA(
"SPI(%d) is not allowed", spi);
145 while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);
146 SPI_I2S_SendData(SPIx, byte);
147 while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET);
148 return (uint8)SPI_I2S_ReceiveData(SPIx);