1 | int main(int argc, char* argv[])
|
2 | {
|
3 | BlinkLed blinkLed;
|
4 | GPIO_InitTypeDef GPIO_InitStructure;
|
5 | SPI_InitTypeDef SPI_InitStructure;
|
6 |
|
7 | blinkLed.powerUp();
|
8 |
|
9 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
10 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
11 |
|
12 | // PB13 = SCK; PB15 = MOSI
|
13 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
|
14 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
15 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
16 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
17 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
18 |
|
19 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_6);
|
20 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_6);
|
21 |
|
22 | // Chip select pin
|
23 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
24 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
25 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
26 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
27 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
28 |
|
29 | GPIO_SetBits(GPIOB, GPIO_Pin_8);
|
30 |
|
31 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
|
32 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
|
33 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
|
34 | SPI_InitStructure.SPI_CRCPolynomial = 1;
|
35 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
36 | SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
|
37 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
38 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
39 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
40 | SPI_Init(SPI2, &SPI_InitStructure);
|
41 |
|
42 | SPI_Cmd(SPI2, ENABLE);
|
43 |
|
44 | uint8_t i = 0;
|
45 |
|
46 | while (1)
|
47 | {
|
48 | i++;
|
49 |
|
50 | blinkLed.turnOff();
|
51 | SPI_SendData8(SPI2, i);
|
52 |
|
53 | while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET)
|
54 | {};
|
55 |
|
56 | blinkLed.turnOn();
|
57 | }
|
58 | }
|