STM8S/A Standard Peripherals Drivers: stm8s_spi.h Source File

STM8S/A

stm8s_spi.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8s_spi.h
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all functions prototype and macros for the SPI peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Define to prevent recursive inclusion -------------------------------------*/
00029 #ifndef __STM8S_SPI_H
00030 #define __STM8S_SPI_H
00031 
00032 /* Includes ------------------------------------------------------------------*/
00033 #include "stm8s.h"
00034 
00035 /** @addtogroup STM8S_StdPeriph_Driver
00036   * @{
00037   */
00038 
00039 /** @addtogroup SPI_Exported_Types
00040   * @{
00041   */
00042 
00043 /**
00044   * @brief  SPI data direction mode
00045   * Warning: element values correspond to BDM, BDOE, RXONLY bits position
00046   */
00047 typedef enum {
00048   SPI_DATADIRECTION_2LINES_FULLDUPLEX = (uint8_t)0x00, /*!< 2-line uni-directional data mode enable */
00049   SPI_DATADIRECTION_2LINES_RXONLY     = (uint8_t)0x04, /*!< Receiver only in 2 line uni-directional data mode */
00050   SPI_DATADIRECTION_1LINE_RX          = (uint8_t)0x80, /*!< Receiver only in 1 line bi-directional data mode */
00051   SPI_DATADIRECTION_1LINE_TX          = (uint8_t)0xC0  /*!< Transmit only in 1 line bi-directional data mode */
00052 } SPI_DataDirection_TypeDef;
00053 
00054 /**
00055   * @brief  SPI Slave Select management
00056   * Warning: element values correspond to LSBFIRST bit position
00057   */
00058 typedef enum
00059 {
00060   SPI_NSS_SOFT  = (uint8_t)0x02, /*!< Software slave management disabled */
00061   SPI_NSS_HARD  = (uint8_t)0x00  /*!< Software slave management enabled */
00062 } SPI_NSS_TypeDef;
00063 
00064 
00065 /**
00066   * @brief  SPI direction transmit/receive
00067   */
00068 
00069 typedef enum {
00070   SPI_DIRECTION_RX = (uint8_t)0x00, /*!< Selects Rx receive direction in bi-directional mode */
00071   SPI_DIRECTION_TX = (uint8_t)0x01  /*!< Selects Tx transmission direction in bi-directional mode */
00072 } SPI_Direction_TypeDef;
00073 
00074 /**
00075   * @brief  SPI master/slave mode
00076   * Warning: element values correspond to MSTR bit position
00077   */
00078 typedef enum {
00079   SPI_MODE_MASTER = (uint8_t)0x04, /*!< SPI Master configuration */
00080   SPI_MODE_SLAVE  = (uint8_t)0x00  /*!< SPI Slave configuration */
00081 } SPI_Mode_TypeDef;
00082 
00083 /**
00084   * @brief  SPI BaudRate Prescaler
00085   * Warning: element values correspond to BR bits position
00086   */
00087 typedef enum {
00088   SPI_BAUDRATEPRESCALER_2   = (uint8_t)0x00, /*!< SPI frequency = frequency(CPU)/2 */
00089   SPI_BAUDRATEPRESCALER_4   = (uint8_t)0x08, /*!< SPI frequency = frequency(CPU)/4 */
00090   SPI_BAUDRATEPRESCALER_8   = (uint8_t)0x10, /*!< SPI frequency = frequency(CPU)/8 */
00091   SPI_BAUDRATEPRESCALER_16  = (uint8_t)0x18, /*!< SPI frequency = frequency(CPU)/16 */
00092   SPI_BAUDRATEPRESCALER_32  = (uint8_t)0x20, /*!< SPI frequency = frequency(CPU)/32 */
00093   SPI_BAUDRATEPRESCALER_64  = (uint8_t)0x28, /*!< SPI frequency = frequency(CPU)/64 */
00094   SPI_BAUDRATEPRESCALER_128 = (uint8_t)0x30, /*!< SPI frequency = frequency(CPU)/128 */
00095   SPI_BAUDRATEPRESCALER_256 = (uint8_t)0x38  /*!< SPI frequency = frequency(CPU)/256 */
00096 } SPI_BaudRatePrescaler_TypeDef;
00097 
00098 /**
00099   * @brief  SPI Clock Polarity
00100   * Warning: element values correspond to CPOL bit position
00101   */
00102 typedef enum {
00103   SPI_CLOCKPOLARITY_LOW  = (uint8_t)0x00, /*!< Clock to 0 when idle */
00104   SPI_CLOCKPOLARITY_HIGH = (uint8_t)0x02  /*!< Clock to 1 when idle */
00105 } SPI_ClockPolarity_TypeDef;
00106 
00107 /**
00108   * @brief  SPI Clock Phase
00109   * Warning: element values correspond to CPHA bit position
00110   */
00111 typedef enum {
00112   SPI_CLOCKPHASE_1EDGE = (uint8_t)0x00, /*!< The first clock transition is the first data capture edge */
00113   SPI_CLOCKPHASE_2EDGE = (uint8_t)0x01  /*!< The second clock transition is the first data capture edge */
00114 } SPI_ClockPhase_TypeDef;
00115 
00116 /**
00117   * @brief  SPI Frame Format: MSB or LSB transmitted first
00118   * Warning: element values correspond to LSBFIRST bit position
00119   */
00120 typedef enum {
00121   SPI_FIRSTBIT_MSB = (uint8_t)0x00, /*!< MSB bit will be transmitted first */
00122   SPI_FIRSTBIT_LSB = (uint8_t)0x80  /*!< LSB bit will be transmitted first */
00123 } SPI_FirstBit_TypeDef;
00124 
00125 /**
00126   * @brief  SPI CRC Transmit/Receive
00127   */
00128 typedef enum {
00129   SPI_CRC_RX = (uint8_t)0x00, /*!< Select Tx CRC register */
00130   SPI_CRC_TX = (uint8_t)0x01  /*!< Select Rx CRC register */
00131 } SPI_CRC_TypeDef;
00132 
00133 /**
00134   * @brief  SPI flags definition - Warning : FLAG value = mapping position register
00135   */
00136 typedef enum {
00137   SPI_FLAG_BSY    = (uint8_t)0x80, /*!< Busy flag */
00138   SPI_FLAG_OVR    = (uint8_t)0x40, /*!< Overrun flag */
00139   SPI_FLAG_MODF   = (uint8_t)0x20, /*!< Mode fault */
00140   SPI_FLAG_CRCERR = (uint8_t)0x10, /*!< CRC error flag */
00141   SPI_FLAG_WKUP   = (uint8_t)0x08, /*!< Wake-up flag */
00142   SPI_FLAG_TXE    = (uint8_t)0x02, /*!< Transmit buffer empty */
00143   SPI_FLAG_RXNE   = (uint8_t)0x01  /*!< Receive buffer empty */
00144 } SPI_Flag_TypeDef;
00145 
00146 /**
00147   * @brief  SPI_IT possible values
00148   * Elements values convention: 0xYX
00149   *   X: Position of the corresponding Interrupt
00150   *   Y: ITPENDINGBIT position
00151   */
00152 typedef enum
00153 {
00154   SPI_IT_WKUP   = (uint8_t)0x34,  /*!< Wake-up interrupt*/
00155   SPI_IT_OVR   = (uint8_t)0x65,  /*!< Overrun interrupt*/
00156   SPI_IT_MODF   = (uint8_t)0x55,  /*!< Mode fault interrupt*/
00157   SPI_IT_CRCERR = (uint8_t)0x45,  /*!< CRC error interrupt*/
00158   SPI_IT_TXE    = (uint8_t)0x17,  /*!< Transmit buffer empty interrupt*/
00159   SPI_IT_RXNE   = (uint8_t)0x06,   /*!< Receive buffer not empty interrupt*/
00160   SPI_IT_ERR    = (uint8_t)0x05   /*!< Error interrupt*/
00161 } SPI_IT_TypeDef;
00162 
00163 /**
00164   * @}
00165   */
00166 
00167 /* Private define ------------------------------------------------------------*/
00168 
00169 /** @addtogroup SPI_Private_Macros
00170   * @brief  Macros used by the assert_param function to check the different functions parameters.
00171   * @{
00172   */
00173 
00174 /**
00175   * @brief  Macro used by the assert_param function in order to check the data direction mode values
00176   */
00177 #define IS_SPI_DATA_DIRECTION_OK(MODE) (((MODE) == SPI_DATADIRECTION_2LINES_FULLDUPLEX) || \
00178                                         ((MODE) == SPI_DATADIRECTION_2LINES_RXONLY) || \
00179                                         ((MODE) == SPI_DATADIRECTION_1LINE_RX) || \
00180                                         ((MODE) == SPI_DATADIRECTION_1LINE_TX))
00181 
00182 /**
00183   * @brief  Macro used by the assert_param function in order to check the mode 
00184   *         half duplex data direction values
00185   */
00186 #define IS_SPI_DIRECTION_OK(DIRECTION) (((DIRECTION) == SPI_DIRECTION_RX) || \
00187                                         ((DIRECTION) == SPI_DIRECTION_TX))
00188 
00189 /**
00190   * @brief  Macro used by the assert_param function in order to check the NSS 
00191   *         management values
00192   */
00193 #define IS_SPI_SLAVEMANAGEMENT_OK(NSS) (((NSS) == SPI_NSS_SOFT) || \
00194                                         ((NSS) == SPI_NSS_HARD))
00195 
00196 
00197 /**
00198   * @brief  Macro used by the assert_param function in order to check the different
00199   *         sensitivity values for the CRC polynomial
00200   */
00201 #define IS_SPI_CRC_POLYNOMIAL_OK(POLYNOMIAL) ((POLYNOMIAL) > (uint8_t)0x00)
00202 
00203 /**
00204   * @brief  Macro used by the assert_param function in order to check the SPI Mode values
00205   */
00206 #define IS_SPI_MODE_OK(MODE) (((MODE) == SPI_MODE_MASTER) || \
00207                               ((MODE) == SPI_MODE_SLAVE))
00208 
00209 /**
00210   * @brief  Macro used by the assert_param function in order to check the baudrate values
00211   */
00212 #define IS_SPI_BAUDRATE_PRESCALER_OK(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \
00213     ((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \
00214     ((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \
00215     ((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \
00216     ((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \
00217     ((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \
00218     ((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \
00219     ((PRESCALER) == SPI_BAUDRATEPRESCALER_256))
00220 
00221 /**
00222   * @brief  Macro used by the assert_param function in order to check the polarity values
00223   */
00224 #define IS_SPI_POLARITY_OK(CLKPOL) (((CLKPOL) == SPI_CLOCKPOLARITY_LOW) || \
00225                                     ((CLKPOL) == SPI_CLOCKPOLARITY_HIGH))
00226 
00227 /**
00228   * @brief  Macro used by the assert_param function in order to check the phase values
00229   */
00230 #define IS_SPI_PHASE_OK(CLKPHA) (((CLKPHA) == SPI_CLOCKPHASE_1EDGE) || \
00231                                  ((CLKPHA) == SPI_CLOCKPHASE_2EDGE))
00232 
00233 /**
00234   * @brief  Macro used by the assert_param function in order to check the first 
00235   *         bit to be transmited values
00236   */
00237 #define IS_SPI_FIRSTBIT_OK(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \
00238                                  ((BIT) == SPI_FIRSTBIT_LSB))
00239 
00240 /**
00241   * @brief  Macro used by the assert_param function in order to check the CRC 
00242   *         Transmit/Receive
00243   */
00244 #define IS_SPI_CRC_OK(CRC) (((CRC) == SPI_CRC_TX) || \
00245                             ((CRC) == SPI_CRC_RX))
00246 
00247 /**
00248   * @brief  Macro used by the assert_param function in order to check the 
00249   *         different flags values
00250   */
00251 #define IS_SPI_FLAGS_OK(FLAG) (((FLAG) == SPI_FLAG_OVR) || \
00252                                ((FLAG) == SPI_FLAG_MODF) || \
00253                                ((FLAG) == SPI_FLAG_CRCERR) || \
00254                                ((FLAG) == SPI_FLAG_WKUP) || \
00255                                ((FLAG) == SPI_FLAG_TXE) || \
00256                                ((FLAG) == SPI_FLAG_RXNE) || \
00257                                ((FLAG) == SPI_FLAG_BSY))
00258 
00259 /**
00260   * @brief  Macro used by the assert_param function in order to check the 
00261   *         different sensitivity values for the flag that can be cleared 
00262   *         by writing 0
00263   */
00264 #define IS_SPI_CLEAR_FLAGS_OK(FLAG) (((FLAG) == SPI_FLAG_CRCERR) || \
00265                                      ((FLAG) == SPI_FLAG_WKUP))
00266 
00267 /**
00268   * @brief  Macro used by the assert_param function in order to check the 
00269   *        different sensitivity values for the Interrupts
00270   */
00271 #define IS_SPI_CONFIG_IT_OK(Interrupt) (((Interrupt) == SPI_IT_TXE)  || \
00272                                         ((Interrupt) == SPI_IT_RXNE)  || \
00273                                         ((Interrupt) == SPI_IT_ERR) || \
00274                                         ((Interrupt) == SPI_IT_WKUP))
00275 
00276 /**
00277   * @brief  Macro used by the assert_param function in order to check the 
00278   *         different sensitivity values for the pending bit
00279   */
00280 #define IS_SPI_GET_IT_OK(ITPendingBit) (((ITPendingBit) == SPI_IT_OVR)  || \
00281                                         ((ITPendingBit) == SPI_IT_MODF) || \
00282                                         ((ITPendingBit) == SPI_IT_CRCERR) || \
00283                                         ((ITPendingBit) == SPI_IT_WKUP) || \
00284                                         ((ITPendingBit) == SPI_IT_TXE)  || \
00285                                         ((ITPendingBit) == SPI_IT_RXNE))
00286 
00287 /**
00288   * @brief  Macro used by the assert_param function in order to check the 
00289   *         different sensitivity values for the pending bit that can be cleared
00290   *         by writing 0
00291   */
00292 #define IS_SPI_CLEAR_IT_OK(ITPendingBit) (((ITPendingBit) == SPI_IT_CRCERR) || \
00293     ((ITPendingBit) == SPI_IT_WKUP))
00294 
00295 /**
00296   * @}
00297   */
00298 
00299 /** @addtogroup SPI_Exported_Functions
00300   * @{
00301   */
00302 void SPI_DeInit(void);
00303 void SPI_Init(SPI_FirstBit_TypeDef FirstBit, 
00304               SPI_BaudRatePrescaler_TypeDef BaudRatePrescaler, 
00305               SPI_Mode_TypeDef Mode, SPI_ClockPolarity_TypeDef ClockPolarity, 
00306               SPI_ClockPhase_TypeDef ClockPhase, 
00307               SPI_DataDirection_TypeDef Data_Direction, 
00308               SPI_NSS_TypeDef Slave_Management, uint8_t CRCPolynomial);
00309 void SPI_Cmd(FunctionalState NewState);
00310 void SPI_ITConfig(SPI_IT_TypeDef SPI_IT, FunctionalState NewState);
00311 void SPI_SendData(uint8_t Data);
00312 uint8_t SPI_ReceiveData(void);
00313 void SPI_NSSInternalSoftwareCmd(FunctionalState NewState);
00314 void SPI_TransmitCRC(void);
00315 void SPI_CalculateCRCCmd(FunctionalState NewState);
00316 uint8_t SPI_GetCRC(SPI_CRC_TypeDef SPI_CRC);
00317 void SPI_ResetCRC(void);
00318 uint8_t SPI_GetCRCPolynomial(void);
00319 void SPI_BiDirectionalLineConfig(SPI_Direction_TypeDef SPI_Direction);
00320 FlagStatus SPI_GetFlagStatus(SPI_Flag_TypeDef SPI_FLAG);
00321 void SPI_ClearFlag(SPI_Flag_TypeDef SPI_FLAG);
00322 ITStatus SPI_GetITStatus(SPI_IT_TypeDef SPI_IT);
00323 void SPI_ClearITPendingBit(SPI_IT_TypeDef SPI_IT);
00324 
00325 /**
00326   * @}
00327   */
00328 
00329 #endif /* __STM8S_SPI_H */
00330 
00331 /**
00332   * @}
00333   */
00334   
00335 
00336 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com