annotate Small_CPU/Src/spi.c @ 48:bf43851a678b

Increased version number
author Ideenmodellierer
date Sun, 29 Jul 2018 18:27:37 +0200
parents 5f11787b4f42
children cd298de33783
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file spi.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 16-Sept-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief Source code for spi control
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 #include "spi.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 //#include "gpio.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /* USER CODE BEGIN 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 #include "scheduler.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 extern void GPIO_new_DEBUG_LOW(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 extern void GPIO_new_DEBUG_HIGH(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 uint8_t data_error = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 uint32_t data_error_time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 static void SPI_Error_Handler(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 /* USER CODE END 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 static uint8_t SPI_check_header_and_footer_ok(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 SPI_HandleTypeDef hspi1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 SPI_HandleTypeDef hspi3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 DMA_HandleTypeDef hdma_tx;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 DMA_HandleTypeDef hdma_rx;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 // SPI3 init function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 void MX_SPI3_Init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 hspi3.Instance = SPI3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 hspi3.Init.Mode = SPI_MODE_MASTER;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 hspi3.Init.Direction = SPI_DIRECTION_2LINES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 hspi3.Init.NSS = SPI_NSS_SOFT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 hspi3.Init.TIMode = SPI_TIMODE_DISABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 hspi3.Init.CRCPolynomial = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 HAL_SPI_Init(&hspi3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 void MX_SPI3_DeInit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 HAL_SPI_DeInit(&hspi3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 uint8_t SPI3_ButtonAdjust(uint8_t *arrayInput, uint8_t *arrayOutput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 HAL_StatusTypeDef status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 uint8_t answer[10];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 uint8_t rework[10];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 uint8_t wait = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 rework[0] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 for(int i = 0; i < 3; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 // limiter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 if(arrayInput[i] == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 arrayInput[i] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 if(arrayInput[i] >= 15)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 rework[i+1] = arrayInput[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 rework[i+3+1] = arrayInput[i] - 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 if(arrayInput[i] >= 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 rework[i+1] = arrayInput[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 rework[i+3+1] = arrayInput[i] - 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 rework[i+1] = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 rework[i+3+1] = 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 status = HAL_OK; /* = 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 for(int i=0;i<7;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 for(int iiii = 0; iiii < 400; iiii++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 wait++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_RESET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 for(int iiii = 0; iiii < 400; iiii++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 wait++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 status += HAL_SPI_TransmitReceive(&hspi3, &rework[i], &answer[i], 1,20);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 for(int iiii = 0; iiii < 400; iiii++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 wait++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 for(int i = 0; i < 3; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 arrayOutput[i] = answer[i+2]; // first not, return of 0xFF not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 // SPI5 init function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 void MX_SPI1_Init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 hspi1.Instance = SPI1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 hspi1.Init.Mode = SPI_MODE_SLAVE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 hspi1.Init.NSS = SPI_NSS_HARD_INPUT;//SPI_NSS_SOFT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;//_DISABLED; _ENABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 hspi1.Init.CRCPolynomial = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 HAL_SPI_Init(&hspi1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 void MX_SPI_DeInit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 HAL_SPI_DeInit(&hspi1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 GPIO_InitTypeDef GPIO_InitStruct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 if(hspi->Instance==SPI1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 // Peripheral clock enable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 __SPI1_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 __GPIOA_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 //PA4 ------> SPI1_CS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 //PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 //PA6 ------> SPI1_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 //PA7 ------> SPI1_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 // GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 //##-3- Configure the DMA streams ##########################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 // Configure the DMA handler for Transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 hdma_tx.Instance = DMA2_Stream3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 hdma_tx.Init.Channel = DMA_CHANNEL_3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 hdma_tx.Init.Mode = DMA_NORMAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 hdma_tx.Init.MemBurst = DMA_MBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 hdma_tx.Init.PeriphBurst = DMA_PBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 HAL_DMA_Init(&hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 // Associate the initialized DMA handle to the the SPI handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 __HAL_LINKDMA(hspi, hdmatx, hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 // Configure the DMA handler for Transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 hdma_rx.Instance = DMA2_Stream0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 hdma_rx.Init.Channel = DMA_CHANNEL_3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 hdma_rx.Init.Mode = DMA_NORMAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 hdma_rx.Init.MemBurst = DMA_MBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 hdma_rx.Init.PeriphBurst = DMA_PBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 HAL_DMA_Init(&hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 // Associate the initialized DMA handle to the the SPI handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 __HAL_LINKDMA(hspi, hdmarx, hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 //##-4- Configure the NVIC for DMA #########################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 //NVIC configuration for DMA transfer complete interrupt (SPI3_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 1, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 // NVIC configuration for DMA transfer complete interrupt (SPI1_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 1, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 if(hspi->Instance==SPI3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 __GPIOC_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 __SPI3_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 //PC10 ------> SPI3_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 //PC11 ------> SPI3_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 //PC12 ------> SPI3_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 //PA15 ------> SPI3_NSS (official)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 //PC9 ------> SPI3_NSS (hw)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 GPIO_InitStruct.Pin = GPIO_PIN_9;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi){
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 if(hspi->Instance==SPI1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 __SPI1_FORCE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 __SPI1_RELEASE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 //PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 //PA6 ------> SPI1_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 //PA7 ------> SPI1_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 HAL_DMA_DeInit(&hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 HAL_DMA_DeInit(&hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 HAL_NVIC_DisableIRQ(DMA2_Stream3_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 HAL_NVIC_DisableIRQ(DMA2_Stream0_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 if(hspi->Instance==SPI3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 __SPI3_FORCE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 __SPI3_RELEASE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 //PC10 ------> SPI3_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 //PC11 ------> SPI3_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 //PC12 ------> SPI3_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 //PA15 ------> SPI3_NSS (official)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 //PC9 ------> SPI3_NSS (hw)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 void SPI_synchronize_with_Master(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 GPIO_InitTypeDef GPIO_InitStruct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 __GPIOA_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 /**SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5) == 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 HAL_Delay(50);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 void SPI_Start_single_TxRx_with_Master(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 uint8_t * pOutput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 if(global.dataSendToSlave.getDeviceDataNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 global.dataSendToSlave.getDeviceDataNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 pOutput = (uint8_t*)&(global.deviceDataSendToMaster);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 pOutput = (uint8_t*)&(global.dataSendToMaster);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 if(HAL_SPI_TransmitReceive_DMA(&hspi1,pOutput, (uint8_t*)&(global.dataSendToSlave), EXCHANGE_BUFFERSIZE+1) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 // Transfer error in transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 SPI_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 global.check_sync_not_running = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 /* stop data exchange? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 if(global.mode == MODE_SHUTDOWN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 global.mode = MODE_SLEEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 global.dataSendToSlavePending = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 global.dataSendToSlaveIsValid = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 global.dataSendToSlaveIsNotValidCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 /* data consistent? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 if(SPI_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 GPIO_new_DEBUG_HIGH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 global.dataSendToSlaveIsValid = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 global.dataSendToSlaveIsNotValidCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 GPIO_new_DEBUG_LOW();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 global.dataSendToSlaveIsValid = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 global.dataSendToSlaveIsNotValidCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 global.dataSendToMaster.power_on_reset = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 global.deviceDataSendToMaster.power_on_reset = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /* no i2c or other time critical threads? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 if(global.dataSendToSlaveIsValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 if(!global.dataSendToSlaveStopEval)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 scheduleSpecial_Evaluate_DataSendToSlave();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 global.dataSendToSlavePending = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 global.dataSendToSlavePending = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* restart SPI */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 if(hspi == &hspi1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 if(global.dataSendToSlaveIsValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 SPI_Start_single_TxRx_with_Master();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 static uint8_t SPI_check_header_and_footer_ok(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 if(global.dataSendToSlave.header.checkCode[0] != 0xBB)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 if(global.dataSendToSlave.header.checkCode[1] != 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 if(global.dataSendToSlave.header.checkCode[2] != 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 if(global.dataSendToSlave.header.checkCode[3] != 0xBB)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 if(global.dataSendToSlave.footer.checkCode[0] != 0xF4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 if(global.dataSendToSlave.footer.checkCode[1] != 0xF3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 if(global.dataSendToSlave.footer.checkCode[2] != 0xF2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 if(global.dataSendToSlave.footer.checkCode[3] != 0xF1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 static void SPI_Error_Handler(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 while(1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/