annotate Small_CPU/Src/spi.c @ 106:d8dc8327f340 FlipDisplay

Starting 'FlipDisplay' branch - No update with regard to OSTC functionality itself - Added option to flip display - Some minor cleanups and code improvments
author Ideenmodellierer
date Tue, 01 Jan 2019 20:57:41 +0100
parents cd298de33783
children a6f0881074a4
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 rework[0] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 for(int i = 0; i < 3; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 // limiter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 if(arrayInput[i] == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 arrayInput[i] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 if(arrayInput[i] >= 15)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 rework[i+1] = arrayInput[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 rework[i+3+1] = arrayInput[i] - 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 if(arrayInput[i] >= 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 rework[i+1] = arrayInput[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 rework[i+3+1] = arrayInput[i] - 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 // copy - auslöse-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 rework[i+1] = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 // wieder-scharf-schalte-schwelle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 rework[i+3+1] = 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 }
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 status = HAL_OK; /* = 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 for(int i=0;i<7;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 {
63
cd298de33783 Replaced wait loop with delay fct
Ideenmodellierer
parents: 38
diff changeset
111 HAL_Delay(10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_RESET);
63
cd298de33783 Replaced wait loop with delay fct
Ideenmodellierer
parents: 38
diff changeset
113 HAL_Delay(10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 status += HAL_SPI_TransmitReceive(&hspi3, &rework[i], &answer[i], 1,20);
63
cd298de33783 Replaced wait loop with delay fct
Ideenmodellierer
parents: 38
diff changeset
115 HAL_Delay(10);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 for(int i = 0; i < 3; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 arrayOutput[i] = answer[i+2]; // first not, return of 0xFF not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 // SPI5 init function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 void MX_SPI1_Init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 hspi1.Instance = SPI1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 hspi1.Init.Mode = SPI_MODE_SLAVE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 hspi1.Init.NSS = SPI_NSS_HARD_INPUT;//SPI_NSS_SOFT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;//_DISABLED; _ENABLED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 hspi1.Init.CRCPolynomial = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 HAL_SPI_Init(&hspi1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 void MX_SPI_DeInit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 HAL_SPI_DeInit(&hspi1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
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 GPIO_InitTypeDef GPIO_InitStruct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 if(hspi->Instance==SPI1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 // Peripheral clock enable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 __SPI1_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 __GPIOA_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 //PA4 ------> SPI1_CS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 //PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 //PA6 ------> SPI1_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 //PA7 ------> SPI1_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 // GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 //##-3- Configure the DMA streams ##########################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 // Configure the DMA handler for Transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 hdma_tx.Instance = DMA2_Stream3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 hdma_tx.Init.Channel = DMA_CHANNEL_3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 hdma_tx.Init.Mode = DMA_NORMAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 hdma_tx.Init.MemBurst = DMA_MBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 hdma_tx.Init.PeriphBurst = DMA_PBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 HAL_DMA_Init(&hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 // Associate the initialized DMA handle to the the SPI handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 __HAL_LINKDMA(hspi, hdmatx, hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 // Configure the DMA handler for Transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 hdma_rx.Instance = DMA2_Stream0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 hdma_rx.Init.Channel = DMA_CHANNEL_3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 hdma_rx.Init.Mode = DMA_NORMAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 hdma_rx.Init.MemBurst = DMA_MBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 hdma_rx.Init.PeriphBurst = DMA_PBURST_INC4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 HAL_DMA_Init(&hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 // Associate the initialized DMA handle to the the SPI handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 __HAL_LINKDMA(hspi, hdmarx, hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 //##-4- Configure the NVIC for DMA #########################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 //NVIC configuration for DMA transfer complete interrupt (SPI3_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 1, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 // NVIC configuration for DMA transfer complete interrupt (SPI1_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 1, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 if(hspi->Instance==SPI3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 __GPIOC_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 __SPI3_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 //PC10 ------> SPI3_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 //PC11 ------> SPI3_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 //PC12 ------> SPI3_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 //PA15 ------> SPI3_NSS (official)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 //PC9 ------> SPI3_NSS (hw)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 GPIO_InitStruct.Pin = GPIO_PIN_9;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi){
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 if(hspi->Instance==SPI1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 __SPI1_FORCE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 __SPI1_RELEASE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 //PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 //PA6 ------> SPI1_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 //PA7 ------> SPI1_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 HAL_DMA_DeInit(&hdma_tx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 HAL_DMA_DeInit(&hdma_rx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 HAL_NVIC_DisableIRQ(DMA2_Stream3_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 HAL_NVIC_DisableIRQ(DMA2_Stream0_IRQn);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 if(hspi->Instance==SPI3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 __SPI3_FORCE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 __SPI3_RELEASE_RESET();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 //SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 //PC10 ------> SPI3_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 //PC11 ------> SPI3_MISO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 //PC12 ------> SPI3_MOSI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 //PA15 ------> SPI3_NSS (official)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 //PC9 ------> SPI3_NSS (hw)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 void SPI_synchronize_with_Master(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 GPIO_InitTypeDef GPIO_InitStruct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 __GPIOA_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 /**SPI1 GPIO Configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 PA5 ------> SPI1_SCK
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 GPIO_InitStruct.Pull = GPIO_PULLUP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5) == 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 HAL_Delay(50);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 void SPI_Start_single_TxRx_with_Master(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 uint8_t * pOutput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 if(global.dataSendToSlave.getDeviceDataNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 global.dataSendToSlave.getDeviceDataNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 pOutput = (uint8_t*)&(global.deviceDataSendToMaster);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 pOutput = (uint8_t*)&(global.dataSendToMaster);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 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
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 // Transfer error in transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 SPI_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 global.check_sync_not_running = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /* stop data exchange? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 if(global.mode == MODE_SHUTDOWN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 global.mode = MODE_SLEEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 global.dataSendToSlavePending = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 global.dataSendToSlaveIsValid = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 global.dataSendToSlaveIsNotValidCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 /* data consistent? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 if(SPI_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 GPIO_new_DEBUG_HIGH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 global.dataSendToSlaveIsValid = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 global.dataSendToSlaveIsNotValidCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 GPIO_new_DEBUG_LOW();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 global.dataSendToSlaveIsValid = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 global.dataSendToSlaveIsNotValidCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 global.dataSendToMaster.power_on_reset = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 global.deviceDataSendToMaster.power_on_reset = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 /* no i2c or other time critical threads? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 if(global.dataSendToSlaveIsValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 if(!global.dataSendToSlaveStopEval)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 scheduleSpecial_Evaluate_DataSendToSlave();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 global.dataSendToSlavePending = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 global.dataSendToSlavePending = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 /* restart SPI */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 if(hspi == &hspi1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 if(global.dataSendToSlaveIsValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 SPI_Start_single_TxRx_with_Master();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 static uint8_t SPI_check_header_and_footer_ok(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 if(global.dataSendToSlave.header.checkCode[0] != 0xBB)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 if(global.dataSendToSlave.header.checkCode[1] != 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 if(global.dataSendToSlave.header.checkCode[2] != 0x01)
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[3] != 0xBB)
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.footer.checkCode[0] != 0xF4)
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.footer.checkCode[1] != 0xF3)
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[2] != 0xF2)
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[3] != 0xF1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 static void SPI_Error_Handler(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 while(1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422
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 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/