|
STM32G474xx HAL 用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_ll_spi.h 00004 * @author MCD Application Team 00005 * @brief SPI LL 模块的头文件。 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2019 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* 定义以防止递归包含 -------------------------------------*/ 00020 #ifndef STM32G4xx_LL_SPI_H 00021 #define STM32G4xx_LL_SPI_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* 包含 ------------------------------------------------------------------*/ 00028 #include "stm32g4xx.h" 00029 00030 /** @addtogroup STM32G4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (SPI1) || defined (SPI2) || defined (SPI3) || defined (SPI4) 00035 00036 /** @defgroup SPI_LL SPI 00037 * @{ 00038 */ 00039 00040 /* 私有类型 -------------------------------------------------------------*/ 00041 /* 私有变量 ---------------------------------------------------------*/ 00042 /* 私有宏 ------------------------------------------------------------*/ 00043 00044 /* 导出的类型 ------------------------------------------------------------*/ 00045 #if defined(USE_FULL_LL_DRIVER) 00046 /** @defgroup SPI_LL_ES_INIT SPI 导出的初始化结构体 00047 * @{ 00048 */ 00049 00050 /** 00051 * @brief SPI 初始化结构体定义 00052 */ 00053 typedef struct 00054 { 00055 uint32_t TransferDirection; /*!< 指定 SPI 单向或双向数据模式。 00056 此参数可以是 @ref SPI_LL_EC_TRANSFER_MODE 的值。 00057 00058 此功能可以使用单元函数 00059 @ref LL_SPI_SetTransferDirection() 进行修改。*/ 00060 00061 uint32_t Mode; /*!< 指定 SPI 模式(主/从)。 00062 此参数可以是 @ref SPI_LL_EC_MODE 的值。 00063 00064 此功能可以使用单元函数 00065 @ref LL_SPI_SetMode() 进行修改。*/ 00066 00067 uint32_t DataWidth; /*!< 指定 SPI 数据宽度。 00068 此参数可以是 @ref SPI_LL_EC_DATAWIDTH 的值。 00069 00070 此功能可以使用单元函数 00071 @ref LL_SPI_SetDataWidth() 进行修改。*/ 00072 00073 uint32_t ClockPolarity; /*!< 指定串行时钟稳态。 00074 此参数可以是 @ref SPI_LL_EC_POLARITY 的值。 00075 00076 此功能可以使用单元函数 00077 @ref LL_SPI_SetClockPolarity() 进行修改。*/ 00078 00079 uint32_t ClockPhase; /*!< 指定用于位捕获的时钟有效边沿。 00080 此参数可以是 @ref SPI_LL_EC_PHASE 的值。 00081 00082 此功能可以使用单元函数 00083 @ref LL_SPI_SetClockPhase() 进行修改。*/ 00084 00085 uint32_t NSS; /*!< 指定 NSS 信号是由硬件(NSS 引脚) 00086 还是通过 SSI 位由软件管理。 00087 此参数可以是 @ref SPI_LL_EC_NSS_MODE 的值。 00088 00089 此功能可以使用单元函数 00090 @ref LL_SPI_SetNSSMode() 进行修改。*/ 00091 00092 uint32_t BaudRate; /*!< 指定用于配置发送和接收 SCK 时钟的波特率预分频器值。 00093 此参数可以是 @ref SPI_LL_EC_BAUDRATEPRESCALER 的值。 00094 @note 通信时钟来自主时钟。 00095 从机时钟无需设置。 00096 00097 此功能可以使用单元函数 00098 @ref LL_SPI_SetBaudRatePrescaler() 进行修改。*/ 00099 00100 00101 uint32_t BitOrder; /*!< 指定数据传输是从 MSB 还是 LSB 位开始。 00102 此参数可以是 @ref SPI_LL_EC_BIT_ORDER 的值。 00103 00104 此功能可以使用单元函数 00105 @ref LL_SPI_SetTransferBitOrder() 进行修改。*/ 00106 00107 uint32_t CRCCalculation; /*!< 指定是否启用 CRC 计算。 00108 此参数可以是 @ref SPI_LL_EC_CRC_CALCULATION 的值。 00109 00110 此功能可以使用单元函数 00111 @ref LL_SPI_EnableCRC() 和 @ref LL_SPI_DisableCRC() 进行修改。*/ 00112 00113 uint32_t CRCPoly; /*!< 指定用于 CRC 计算的多项式。 00114 此参数必须是 Min_Data = 0x00 和 Max_Data = 0xFFFF 之间的数字。 00115 00116 此功能可以使用单元函数 00117 @ref LL_SPI_SetCRCPolynomial() 进行修改。*/ 00118 00119 } LL_SPI_InitTypeDef; 00120 00121 /** 00122 * @} 00123 */ 00124 #endif /* USE_FULL_LL_DRIVER */ 00125 00126 /* 导出的常量 --------------------------------------------------------*/ 00127 /** @defgroup SPI_LL_Exported_Constants SPI 导出的常量 00128 * @{ 00129 */ 00130 00131 /** @defgroup SPI_LL_EC_GET_FLAG 获取标志位定义 00132 * @brief 可与 LL_SPI_ReadReg 函数一起使用的标志位定义 00133 * @{ 00134 */ 00135 #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< 接收缓冲区非空标志 */ 00136 #define LL_SPI_SR_TXE SPI_SR_TXE /*!< 发送缓冲区空标志 */ 00137 #define LL_SPI_SR_BSY SPI_SR_BSY /*!< 忙标志 */ 00138 #define LL_SPI_SR_CRCERR SPI_SR_CRCERR /*!< CRC 错误标志 */ 00139 #define LL_SPI_SR_MODF SPI_SR_MODF /*!< 模式故障标志 */ 00140 #define LL_SPI_SR_OVR SPI_SR_OVR /*!< 溢出标志 */ 00141 #define LL_SPI_SR_FRE SPI_SR_FRE /*!< TI 模式帧格式错误标志 */ 00142 /** 00143 * @} 00144 */ 00145 00146 /** @defgroup SPI_LL_EC_IT 中断定义 00147 * @brief 可与 LL_SPI_ReadReg 和 LL_SPI_WriteReg 函数一起使用的中断定义 00148 * @{ 00149 */ 00150 #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< 接收缓冲区非空中断使能 */ 00151 #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< 发送缓冲区空中断使能 */ 00152 #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< 错误中断使能 */ 00153 /** 00154 * @} 00155 */ 00156 00157 /** @defgroup SPI_LL_EC_MODE 操作模式 00158 * @{ 00159 */ 00160 #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< 主机配置 */ 00161 #define LL_SPI_MODE_SLAVE 0x