11 #ifndef __MG32F10x_SPI_H 12 #define __MG32F10x_SPI_H 36 uint16_t SPI_TransferMode;
37 uint16_t SPI_DataSize;
40 uint16_t SPI_BaudRatePrescaler;
41 uint16_t SPI_FrameFormat;
50 uint16_t SPI_MicrowireControlFrameSize;
51 uint16_t SPI_MicrowireTransferMode;
52 uint16_t SPI_MicrowireDirection;
53 uint16_t SPI_MicrowireHandshaking;
62 uint16_t SPI_EnhancedSpiTransferType;
63 uint16_t SPI_EnhancedSpiInstructionLength;
64 uint16_t SPI_EnhancedSpiAddressLength;
65 uint16_t SPI_EnhancedSpiWaitCycles;
77 #define SPI_TransferMode_TxAndRx ((uint16_t)SPI_CR0_TMOD_TX_AND_RX) 78 #define SPI_TransferMode_TxOnly ((uint16_t)SPI_CR0_TMOD_TX_ONLY) 79 #define SPI_TransferMode_RxOnly ((uint16_t)SPI_CR0_TMOD_RX_ONLY) 80 #define SPI_TransferMode_EepromRead ((uint16_t)SPI_CR0_TMOD_EEPROM_READ) 89 #define SPI_DataSize_4b ((uint16_t)SPI_CR0_DFS_4BITS) 90 #define SPI_DataSize_5b ((uint16_t)SPI_CR0_DFS_5BITS) 91 #define SPI_DataSize_6b ((uint16_t)SPI_CR0_DFS_6BITS) 92 #define SPI_DataSize_7b ((uint16_t)SPI_CR0_DFS_7BITS) 93 #define SPI_DataSize_8b ((uint16_t)SPI_CR0_DFS_8BITS) 94 #define SPI_DataSize_9b ((uint16_t)SPI_CR0_DFS_9BITS) 95 #define SPI_DataSize_10b ((uint16_t)SPI_CR0_DFS_10BITS) 96 #define SPI_DataSize_11b ((uint16_t)SPI_CR0_DFS_11BITS) 97 #define SPI_DataSize_12b ((uint16_t)SPI_CR0_DFS_12BITS) 98 #define SPI_DataSize_13b ((uint16_t)SPI_CR0_DFS_13BITS) 99 #define SPI_DataSize_14b ((uint16_t)SPI_CR0_DFS_14BITS) 100 #define SPI_DataSize_15b ((uint16_t)SPI_CR0_DFS_15BITS) 101 #define SPI_DataSize_16b ((uint16_t)SPI_CR0_DFS_16BITS) 110 #define SPI_CPOL_Low ((uint16_t)0x00) 111 #define SPI_CPOL_High ((uint16_t)0x80) 120 #define SPI_CPHA_1Edge ((uint16_t)0x00) 121 #define SPI_CPHA_2Edge ((uint16_t)0x40) 130 #define SPI_FrameFormat_SPI ((uint16_t)SPI_CR0_FRF_SPI) 131 #define SPI_FrameFormat_SSP ((uint16_t)SPI_CR0_FRF_SSP) 132 #define SPI_FrameFormat_Microwire ((uint16_t)SPI_CR0_FRF_NS) 141 #define SPI_MicrowireControlFrameSize_1b ((uint16_t)SPI_CR0_CFS_01_BIT) 142 #define SPI_MicrowireControlFrameSize_2b ((uint16_t)SPI_CR0_CFS_02_BIT) 143 #define SPI_MicrowireControlFrameSize_3b ((uint16_t)SPI_CR0_CFS_03_BIT) 144 #define SPI_MicrowireControlFrameSize_4b ((uint16_t)SPI_CR0_CFS_04_BIT) 145 #define SPI_MicrowireControlFrameSize_5b ((uint16_t)SPI_CR0_CFS_05_BIT) 146 #define SPI_MicrowireControlFrameSize_6b ((uint16_t)SPI_CR0_CFS_06_BIT) 147 #define SPI_MicrowireControlFrameSize_7b ((uint16_t)SPI_CR0_CFS_07_BIT) 148 #define SPI_MicrowireControlFrameSize_8b ((uint16_t)SPI_CR0_CFS_08_BIT) 149 #define SPI_MicrowireControlFrameSize_9b ((uint16_t)SPI_CR0_CFS_09_BIT) 150 #define SPI_MicrowireControlFrameSize_10b ((uint16_t)SPI_CR0_CFS_10_BIT) 151 #define SPI_MicrowireControlFrameSize_11b ((uint16_t)SPI_CR0_CFS_11_BIT) 152 #define SPI_MicrowireControlFrameSize_12b ((uint16_t)SPI_CR0_CFS_12_BIT) 153 #define SPI_MicrowireControlFrameSize_13b ((uint16_t)SPI_CR0_CFS_13_BIT) 154 #define SPI_MicrowireControlFrameSize_14b ((uint16_t)SPI_CR0_CFS_14_BIT) 155 #define SPI_MicrowireControlFrameSize_15b ((uint16_t)SPI_CR0_CFS_15_BIT) 156 #define SPI_MicrowireControlFrameSize_16b ((uint16_t)SPI_CR0_CFS_16_BIT) 165 #define SPI_MicrowireTransferMode_NonSequential ((uint16_t)0x00) 166 #define SPI_MicrowireTransferMode_Sequential ((uint16_t)0x01) 175 #define SPI_MicrowireDirection_Receive ((uint16_t)0x00) 176 #define SPI_MicrowireDirection_Transmit ((uint16_t)0x02) 185 #define SPI_MicrowireHandshaking_Enable ((uint16_t)0x04) 186 #define SPI_MicrowireHandshaking_Disable ((uint16_t)0x00) 195 #define SPI_SpiMode_Standard (SPI_CR0_SPI_MODE_STD) 196 #define SPI_SpiMode_Dual (SPI_CR0_SPI_MODE_DUAL) 197 #define SPI_SpiMode_Quad (SPI_CR0_SPI_MODE_QUAD) 206 #define SPI_EnhancedSpiTransferType_0 ((uint16_t)0x00) 207 #define SPI_EnhancedSpiTransferType_1 ((uint16_t)0x01) 208 #define SPI_EnhancedSpiTransferType_2 ((uint16_t)0x02) 217 #define SPI_EnhancedSpiInstructionLength_0b ((uint16_t)SPI_ESPICR_INSTL_0BIT) 218 #define SPI_EnhancedSpiInstructionLength_4b ((uint16_t)SPI_ESPICR_INSTL_4BIT) 219 #define SPI_EnhancedSpiInstructionLength_8b ((uint16_t)SPI_ESPICR_INSTL_8BIT) 220 #define SPI_EnhancedSpiInstructionLength_16b ((uint16_t)SPI_ESPICR_INSTL_16BIT) 229 #define SPI_EnhancedSpiAddressLength_0b ((uint16_t)SPI_ESPICR_ADDRL_0BIT) 230 #define SPI_EnhancedSpiAddressLength_4b ((uint16_t)SPI_ESPICR_ADDRL_4BIT) 231 #define SPI_EnhancedSpiAddressLength_8b ((uint16_t)SPI_ESPICR_ADDRL_8BIT) 232 #define SPI_EnhancedSpiAddressLength_12b ((uint16_t)SPI_ESPICR_ADDRL_12BIT) 233 #define SPI_EnhancedSpiAddressLength_16b ((uint16_t)SPI_ESPICR_ADDRL_16BIT) 234 #define SPI_EnhancedSpiAddressLength_20b ((uint16_t)SPI_ESPICR_ADDRL_20BIT) 235 #define SPI_EnhancedSpiAddressLength_24b ((uint16_t)SPI_ESPICR_ADDRL_24BIT) 236 #define SPI_EnhancedSpiAddressLength_28b ((uint16_t)SPI_ESPICR_ADDRL_28BIT) 237 #define SPI_EnhancedSpiAddressLength_32b ((uint16_t)SPI_ESPICR_ADDRL_32BIT) 238 #define SPI_EnhancedSpiAddressLength_36b ((uint16_t)SPI_ESPICR_ADDRL_36BIT) 239 #define SPI_EnhancedSpiAddressLength_40b ((uint16_t)SPI_ESPICR_ADDRL_40BIT) 240 #define SPI_EnhancedSpiAddressLength_44b ((uint16_t)SPI_ESPICR_ADDRL_44BIT) 241 #define SPI_EnhancedSpiAddressLength_48b ((uint16_t)SPI_ESPICR_ADDRL_48BIT) 242 #define SPI_EnhancedSpiAddressLength_52b ((uint16_t)SPI_ESPICR_ADDRL_52BIT) 243 #define SPI_EnhancedSpiAddressLength_56b ((uint16_t)SPI_ESPICR_ADDRL_56BIT) 244 #define SPI_EnhancedSpiAddressLength_60b ((uint16_t)SPI_ESPICR_ADDRL_60BIT) 253 #define SPI_NSS_0 (0x01) 254 #define SPI_NSS_1 (0x02) 255 #define SPI_NSS_2 (0x04) 264 #define SPI_FLAG_BUSY ((uint8_t)SPI_SR_BUSY) 265 #define SPI_FLAG_TFNF ((uint8_t)SPI_SR_TFNF) 266 #define SPI_FLAG_TFE ((uint8_t)SPI_SR_TFE) 267 #define SPI_FLAG_RFNE ((uint8_t)SPI_SR_RFNE) 268 #define SPI_FLAG_RFF ((uint8_t)SPI_SR_RFF) 269 #define SPI_FLAG_TXERR ((uint8_t)SPI_SR_TXERR) 270 #define SPI_FLAG_DCOL ((uint8_t)SPI_SR_DCOL) 279 #define SPI_IT_TXE (0x1 << 0) 280 #define SPI_IT_TXO (0x1 << 1) 281 #define SPI_IT_RXU (0x1 << 2) 282 #define SPI_IT_RXO (0x1 << 3) 283 #define SPI_IT_RXF (0x1 << 4) 284 #define SPI_IT_MST (0x1 << 5) 293 #define SPI_DMAReq_Rx 0x01 294 #define SPI_DMAReq_Tx 0x02 Definition: mg32f10x.h:571
void SPI_ReceiveDataLengthConfig(SPI_TypeDef *SPIx, uint32_t DataLength)
Configures the number of data frames to be continuously received (only used for SPIMx).
Definition: mg32f10x_spi.c:207
void SPI_NSSToggleModeCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the slave select toggle mode.
Definition: mg32f10x_spi.c:189
SPI Microwire Init structure definition.
Definition: mg32f10x_spi.h:48
uint8_t SPI_GetRxFIFOLevel(SPI_TypeDef *SPIx)
Returns the number of data can be read from Rx FIFO.
Definition: mg32f10x_spi.c:513
void SPI_MicrowireConfig(SPI_TypeDef *SPIx, SPI_MicrowireInitTypeDef *SPI_MicrowireInitStruct)
Configures the Microwire frame format according to the specified parameters in the SPI_MicrowireInitS...
Definition: mg32f10x_spi.c:222
void SPI_EnhancedSpiConfig(SPI_TypeDef *SPIx, SPI_EnhancedSpiInitTypeDef *SPI_EnhancedSpiInitStruct)
Configures the Enhanced SPI Mode according to the specified parameters in the SPI_EnhancedSpiInitStru...
Definition: mg32f10x_spi.c:268
void SPI_StructInit(SPI_InitTypeDef *SPI_InitStruct)
Fills each SPI_InitStruct member with its default value.
Definition: mg32f10x_spi.c:90
void SPI_ClearITPendingBit(SPI_TypeDef *SPIx, uint8_t SPI_IT)
Clears the SPIx's interrupt pending bits.
Definition: mg32f10x_spi.c:462
ITStatus SPI_GetITStatus(SPI_TypeDef *SPIx, uint8_t SPI_IT)
Checks whether the specified SPIx interrupt has occurred or not.
Definition: mg32f10x_spi.c:430
void SPI_DMACmd(SPI_TypeDef *SPIx, uint32_t SPI_DMAReq, FunctionalState NewState)
Enables or disables the SPIx's DMA interface.
Definition: mg32f10x_spi.c:571
uint8_t SPI_GetTxFIFOLevel(SPI_TypeDef *SPIx)
Returns the number of data left in Tx FIFO.
Definition: mg32f10x_spi.c:525
void SPI_DMATxReqLevelConfig(SPI_TypeDef *SPIx, uint8_t DMATxReqLevel)
Configures the DMA Tx request level.
Definition: mg32f10x_spi.c:553
uint16_t SPI_ReadData(SPI_TypeDef *SPIx)
Read one data from Rx FIFO.
Definition: mg32f10x_spi.c:297
void SPI_NSSConfig(SPI_TypeDef *SPIx, uint32_t SPI_NSS, FunctionalState NewState)
Enables or disables the specified slave select line (only used for SPIMx).
Definition: mg32f10x_spi.c:170
void SPI_WriteData(SPI_TypeDef *SPIx, uint16_t data)
Write one data to Tx FIFO.
Definition: mg32f10x_spi.c:310
void SPI_RxdSampleDelayConfig(SPI_TypeDef *SPIx, uint8_t DelayValue)
Configures the rxd sample delay value.
Definition: mg32f10x_spi.c:589
SPI Enhanced SPI Mode Init structure definition.
Definition: mg32f10x_spi.h:60
void SPI_RxFIFOThresholdConfig(SPI_TypeDef *SPIx, uint8_t Threshold)
Configures the Rx FIFO threshold.
Definition: mg32f10x_spi.c:487
void SPI_EnhancedSpiStructInit(SPI_EnhancedSpiInitTypeDef *SPI_EnhancedSpiInitStruct)
Fills each SPI_EnhancedSpiInitStruct member with its default value.
Definition: mg32f10x_spi.c:282
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.
Definition: mg32f10x_spi.c:75
void SPI_TxFIFOThresholdConfig(SPI_TypeDef *SPIx, uint8_t Threshold)
Configures the Tx FIFO threshold.
Definition: mg32f10x_spi.c:501
ITStatus SPI_GetRawITStatus(SPI_TypeDef *SPIx, uint8_t SPI_IT)
Checks whether the specified SPIx raw interrupt status.
Definition: mg32f10x_spi.c:396
void SPI_DeInit(SPI_TypeDef *SPIx)
Deinitializes the SPIx peripheral registers to their default reset values.
Definition: mg32f10x_spi.c:40
SPI Init structure definition.
Definition: mg32f10x_spi.h:34
void SPI_MicrowireStructInit(SPI_MicrowireInitTypeDef *SPI_MicrowireInitStruct)
Fills each SPI_MicrowireInitStruct member with its default value.
Definition: mg32f10x_spi.c:235
void SPI_SlaveOutputCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the slave output (only used for SPISx).
Definition: mg32f10x_spi.c:146
void SPI_ITConfig(SPI_TypeDef *SPIx, uint8_t SPI_IT, FunctionalState NewState)
Enables or disables the specified SPI interrupts.
Definition: mg32f10x_spi.c:367
void SPI_SpiModeConfig(SPI_TypeDef *SPIx, uint32_t SPI_SpiMode)
Configures the Spi Mode.
Definition: mg32f10x_spi.c:254
void SPI_TransferModeConfig(SPI_TypeDef *SPIx, uint16_t SPI_TransferMode)
Configures the transfer mode.
Definition: mg32f10x_spi.c:132
FlagStatus SPI_GetFlagStatus(SPI_TypeDef *SPIx, uint8_t SPI_FLAG)
Checks whether the specified SPIx flag is set or not.
Definition: mg32f10x_spi.c:331
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
Definition: mg32f10x_spi.c:109
void SPI_DMARxReqLevelConfig(SPI_TypeDef *SPIx, uint8_t DMARxReqLevel)
Configures the DMA Rx request level.
Definition: mg32f10x_spi.c:539