1 | /* Includes ------------------------------------------------------------------*/
|
2 | #include "stm32f10x.h"
|
3 |
|
4 |
|
5 |
|
6 | /* Private typedef -----------------------------------------------------------*/
|
7 |
|
8 | /* Private define ------------------------------------------------------------*/
|
9 | #define BufferSize 32
|
10 |
|
11 | /* Private macro -------------------------------------------------------------*/
|
12 | /* Private variables ---------------------------------------------------------*/
|
13 | SPI_InitTypeDef SPI_InitStructure;
|
14 | DMA_InitTypeDef DMA_InitStructure;
|
15 | GPIO_InitTypeDef GPIO_InitStructure;
|
16 |
|
17 |
|
18 | /* Private function prototypes -----------------------------------------------*/
|
19 | void RCC_Configuration(void);
|
20 | void GPIO_Configuration(void);
|
21 |
|
22 | /* Private functions ---------------------------------------------------------*/
|
23 |
|
24 | /**
|
25 | * @brief Main program
|
26 | * @param None
|
27 | * @retval None
|
28 | */
|
29 | int main(void)
|
30 | {
|
31 |
|
32 |
|
33 | /* System clocks configuration ---------------------------------------------*/
|
34 | RCC_Configuration();
|
35 |
|
36 | /* GPIO configuration ------------------------------------------------------*/
|
37 | GPIO_Configuration();
|
38 |
|
39 |
|
40 |
|
41 | // SPI_MASTER configuration ------------------------------------------------------
|
42 | SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
|
43 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
44 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
|
45 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
|
46 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
47 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
48 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
|
49 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
50 | SPI_InitStructure.SPI_CRCPolynomial = 7;
|
51 | SPI_Init(SPI1, &SPI_InitStructure);
|
52 |
|
53 | // Take NSS line high by default
|
54 | GPIO_SetBits(GPIOA, GPIO_Pin_4);
|
55 |
|
56 |
|
57 |
|
58 | /* Enable SPI_MASTER */
|
59 | SPI_Cmd(SPI1, ENABLE);
|
60 |
|
61 |
|
62 | while (1)
|
63 | {
|
64 |
|
65 |
|
66 |
|
67 | GPIO_ResetBits(GPIOA, GPIO_Pin_4);
|
68 |
|
69 | // SPI_I2S_SendData(SPI1, 0b1100000000000000);
|
70 | SPI_I2S_SendData(SPI1, 0b1011000000000000); //Clear DAC Output to zero
|
71 |
|
72 |
|
73 | while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET)
|
74 | {}
|
75 |
|
76 |
|
77 | GPIO_SetBits(GPIOA, GPIO_Pin_4);
|
78 |
|
79 |
|
80 | }
|
81 |
|
82 |
|
83 | }
|
84 |
|
85 |
|
86 | void RCC_Configuration(void)
|
87 | {
|
88 | /* PCLK2 = HCLK/2 */
|
89 | RCC_PCLK2Config(RCC_HCLK_Div2);
|
90 |
|
91 | /* Enable peripheral clocks --------------------------------------------------*/
|
92 |
|
93 |
|
94 | /* Enable SPI_MASTER clock and GPIO clock for SPI_MASTER and SPI_SLAVE */
|
95 |
|
96 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 ,ENABLE);
|
97 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ,ENABLE);
|
98 |
|
99 | }
|
100 |
|
101 | void GPIO_Configuration(void)
|
102 | {
|
103 | GPIO_InitTypeDef GPIO_InitStructure;
|
104 |
|
105 |
|
106 |
|
107 | /* Configure SPI_MASTER pins: NSS, SCK and MOSI */
|
108 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_5 ;
|
109 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
110 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
111 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
112 |
|
113 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
|
114 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
115 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
116 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
117 |
|
118 |
|
119 | }
|