spi.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file spi.c
  5. * @brief This file provides code for the configuration
  6. * of the SPI instances.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2022 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "spi.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. /* SPI1 init function */
  25. void MX_SPI1_Init(void)
  26. {
  27. /* USER CODE BEGIN SPI1_Init 0 */
  28. /* USER CODE END SPI1_Init 0 */
  29. LL_SPI_InitTypeDef SPI_InitStruct = {0};
  30. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  31. /* Peripheral clock enable */
  32. LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1);
  33. LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
  34. /**SPI1 GPIO Configuration
  35. PA5 ------> SPI1_SCK
  36. PA6 ------> SPI1_MISO
  37. PA7 ------> SPI1_MOSI
  38. */
  39. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  40. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  41. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  42. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  43. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  44. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  45. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  46. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  47. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  48. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  49. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  50. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  51. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  52. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  53. GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
  54. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  55. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  56. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  57. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  58. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  59. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  60. /* USER CODE BEGIN SPI1_Init 1 */
  61. /* USER CODE END SPI1_Init 1 */
  62. SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  63. SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  64. SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  65. SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
  66. SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
  67. SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  68. SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4;
  69. SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  70. SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  71. SPI_InitStruct.CRCPoly = 7;
  72. LL_SPI_Init(SPI1, &SPI_InitStruct);
  73. LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  74. LL_SPI_EnableNSSPulseMgt(SPI1);
  75. /* USER CODE BEGIN SPI1_Init 2 */
  76. /* USER CODE END SPI1_Init 2 */
  77. }
  78. /* USER CODE BEGIN 1 */
  79. /* USER CODE END 1 */