1 | GPIO_InitTypeDef GPIO_InitStructure;
|
2 | SPI_InitTypeDef SPI_InitStructure;
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
|
9 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
|
10 |
|
11 | // PortA Pin5 SCLK; Pin7 MOSI; Pin6 MISO und PortB Pin6 cs
|
12 |
|
13 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
|
14 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
15 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
|
16 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
17 |
|
18 |
|
19 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
20 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
21 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
|
22 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
23 |
|
24 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
25 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
26 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
|
27 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
28 |
|
29 | GPIO_SetBits(GPIOB, GPIO_Pin_6);
|
30 |
|
31 | GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);
|
32 | GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
|
33 | GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
|
34 |
|
35 |
|
36 |
|
37 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
|
38 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
39 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
40 |
|
41 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
42 | SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
43 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
44 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
45 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
46 | SPI_Init(SPI1, &SPI_InitStructure);
|
47 |
|
48 | SPI_Cmd(SPI1, ENABLE);
|