| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

SPI_Slave_Polling_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : SPI_Slave_Polling_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the SPI slave functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
190 /* Includes ------------------------------------------------------------------*/
191 #include "BlueNRG1.h"
192 #include "BlueNRG1_conf.h"
193 #include "SDK_EVAL_Config.h"
194
207 /* Private typedef -----------------------------------------------------------*/
208 /* Private define ------------------------------------------------------------*/
209 #define TOGGLE_DL1 '1'
210 #define TOGGLE_DL2 '2'
211 #define TOGGLE_DL3 '3'
212
213 /* Chip Select pin used for the Slave_Polling demo */
214 #define SPI_CS_SLAVE_DEMO_PIN GPIO_Pin_11
215 #define SPI_CS_SLAVE_DEMO_MODE Serial0_Mode
216
217
218 /* Private macro -------------------------------------------------------------*/
219 /* Private variables ---------------------------------------------------------*/
220 /* Private function prototypes -----------------------------------------------*/
221 void processCommand(void);
222 void SPI_Slave_Configuration(void);
223
224 /* Private functions ---------------------------------------------------------*/
225
231 int main(void)
232 {
233 /* System initialization function */
234 SystemInit();
235
236 /* Identify BlueNRG1 platform */
237 SdkEvalIdentification();
238
239 /* LEDS initialization */
240 SdkEvalLedInit(LED1);
241 SdkEvalLedInit(LED2);
242 SdkEvalLedInit(LED3);
243
244 /* SPI initialization */
245 SPI_Slave_Configuration();
246
247 /* Infinite loop for process command */
248 processCommand();
249
250 }
251
257 void processCommand(void)
258 {
259 uint8_t command;
260
261 /* Infinite loop */
262 while(1) {
263
264 /* Loop until the UART Receive Data Register is not empty */
265 while (SPI_GetFlagStatus(SPI_FLAG_RNE) == RESET);
266
267 /* Read command received from SPI master */
268 command = SPI_ReceiveData();
269
270 /* Parse the command */
271 if(command == TOGGLE_DL1) {
272 SdkEvalLedToggle(LED1);
273 }
274 else if(command == TOGGLE_DL2) {
275 SdkEvalLedToggle(LED2);
276 }
277 else if(command == TOGGLE_DL3) {
278 SdkEvalLedToggle(LED3);
279 }
280
281 }
282 }
283
284
290 void SPI_Slave_Configuration(void)
291 {
292 SPI_InitType SPI_InitStructure;
293 GPIO_InitType GPIO_InitStructure;
294
295 /* Enable SPI and GPIO clocks */
296 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_SPI, ENABLE);
297
298 /* Configure SPI pins */
299 GPIO_StructInit(&GPIO_InitStructure);
300 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_SPI_PERIPH_MOSI_PIN;
301 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_SPI_PERIPH_MOSI_MODE;
302 GPIO_InitStructure.GPIO_Pull = ENABLE;
303 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
304 GPIO_Init(&GPIO_InitStructure);
305
306 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_SPI_PERIPH_MISO_PIN;
307 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_SPI_PERIPH_MISO_MODE;
308 GPIO_Init(&GPIO_InitStructure);
309
310 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_SPI_PERIPH_SCLK_PIN;
311 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_SPI_PERIPH_SCLK_MODE;
312 GPIO_Init(&GPIO_InitStructure);
313
314 GPIO_InitStructure.GPIO_Pin = SPI_CS_SLAVE_DEMO_PIN;
315 GPIO_InitStructure.GPIO_Mode = SPI_CS_SLAVE_DEMO_MODE;
316 GPIO_Init(&GPIO_InitStructure);
317
318 /* Configure SPI in master mode */
319 SPI_StructInit(&SPI_InitStructure);
320 SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;;
321 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b ;
322 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
323 SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
324 SPI_InitStructure.SPI_BaudRate = SPI_BAUDRATE;
325 SPI_Init(&SPI_InitStructure);
326
327 /* Clear RX and TX FIFO */
328 SPI_ClearTXFIFO();
329 SPI_ClearRXFIFO();
330
331 /* Enable SPI functionality */
332 SPI_Cmd(ENABLE);
333
334 }
335
336 #ifdef USE_FULL_ASSERT
337
344 void assert_failed(uint8_t* file, uint32_t line)
345 {
346 /* User can add his own implementation to report the file name and line number,
347 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
348
349 /* Infinite loop */
350 while (1)
351 {
352 }
353 }
354
355 #endif
356
369 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
SPI_CS_SLAVE_DEMO_MODE
#define SPI_CS_SLAVE_DEMO_MODE
Definition: SPI_Slave_Polling_main.c:215
SPI_Slave_Configuration
void SPI_Slave_Configuration(void)
SPI Slave initialization.
Definition: SPI_Slave_Polling_main.c:290
processCommand
void processCommand(void)
Process command code.
Definition: SPI_Slave_Polling_main.c:257
TOGGLE_DL3
#define TOGGLE_DL3
Definition: SPI_Slave_Polling_main.c:211
SPI_CS_SLAVE_DEMO_PIN
#define SPI_CS_SLAVE_DEMO_PIN
Definition: SPI_Slave_Polling_main.c:214
TOGGLE_DL1
#define TOGGLE_DL1
Definition: SPI_Slave_Polling_main.c:209
TOGGLE_DL2
#define TOGGLE_DL2
Definition: SPI_Slave_Polling_main.c:210
main
int main(void)
Main program code.
Definition: SPI_Slave_Polling_main.c:231