source: S-port/trunk/Core/Src/spi.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 3.3 KB
Line 
1/**
2 ******************************************************************************
3 * @file spi.c
4 * @brief This file provides code for the configuration
5 * of the SPI instances.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under Ultimate Liberty license
13 * SLA0044, the "License"; You may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at:
15 * www.st.com/SLA0044
16 *
17 ******************************************************************************
18 */
19
20/* Includes ------------------------------------------------------------------*/
21#include "spi.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27SPI_HandleTypeDef hspi3;
28
29/* SPI3 init function */
30void MX_SPI3_Init(void)
31{
32
33 /* USER CODE BEGIN SPI3_Init 0 */
34
35 /* USER CODE END SPI3_Init 0 */
36
37 /* USER CODE BEGIN SPI3_Init 1 */
38
39 /* USER CODE END SPI3_Init 1 */
40 hspi3.Instance = SPI3;
41 hspi3.Init.Mode = SPI_MODE_MASTER;
42 hspi3.Init.Direction = SPI_DIRECTION_2LINES;
43 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
44 hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
45 hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
46 hspi3.Init.NSS = SPI_NSS_SOFT;
47 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
48 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
49 hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
50 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
51 hspi3.Init.CRCPolynomial = 10;
52 if (HAL_SPI_Init(&hspi3) != HAL_OK)
53 {
54 Error_Handler();
55 }
56 //hspi3.Instance->CR1 = SPI_CR1_SPE;
57 /* USER CODE BEGIN SPI3_Init 2 */
58
59 /* USER CODE END SPI3_Init 2 */
60
61}
62
63void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
64{
65
66 GPIO_InitTypeDef GPIO_InitStruct = {0};
67 if(spiHandle->Instance==SPI3)
68 {
69 /* USER CODE BEGIN SPI3_MspInit 0 */
70
71 /* USER CODE END SPI3_MspInit 0 */
72 /* SPI3 clock enable */
73 __HAL_RCC_SPI3_CLK_ENABLE();
74
75 __HAL_RCC_GPIOC_CLK_ENABLE();
76 /**SPI3 GPIO Configuration
77 PC10 ------> SPI3_SCK
78 PC11 ------> SPI3_MISO
79 PC12 ------> SPI3_MOSI
80 */
81 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
82 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
83 GPIO_InitStruct.Pull = GPIO_NOPULL;
84 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
85 GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
86 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
87
88 /* USER CODE BEGIN SPI3_MspInit 1 */
89
90 /* USER CODE END SPI3_MspInit 1 */
91 }
92}
93
94void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
95{
96
97 if(spiHandle->Instance==SPI3)
98 {
99 /* USER CODE BEGIN SPI3_MspDeInit 0 */
100
101 /* USER CODE END SPI3_MspDeInit 0 */
102 /* Peripheral clock disable */
103 __HAL_RCC_SPI3_CLK_DISABLE();
104
105 /**SPI3 GPIO Configuration
106 PC10 ------> SPI3_SCK
107 PC11 ------> SPI3_MISO
108 PC12 ------> SPI3_MOSI
109 */
110 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
111
112 /* USER CODE BEGIN SPI3_MspDeInit 1 */
113
114 /* USER CODE END SPI3_MspDeInit 1 */
115 }
116}
117
118/* USER CODE BEGIN 1 */
119
120/* USER CODE END 1 */
121
122/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.