STM8L15x Standard Peripherals Drivers: SPI

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

SPI driver modules. More...

Modules

 SPI_Exported_Types
 SPI_Exported_Macros
 

Macros used by the assert_param function to check the different functions parameters.

 SPI_Private_Functions

Functions

void SPI_BiDirectionalLineConfig (SPI_TypeDef *SPIx, SPI_Direction_TypeDef SPI_Direction)
 Selects the data transfer direction in Bi-directional mode.
void SPI_CalculateCRCCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the CRC value calculation of the transferred bytes.
void SPI_ClearFlag (SPI_TypeDef *SPIx, SPI_FLAG_TypeDef SPI_FLAG)
 Clears the SPI flags.
void SPI_ClearITPendingBit (SPI_TypeDef *SPIx, SPI_IT_TypeDef SPI_IT)
 Clears the interrupt pending bits.
void SPI_Cmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the SPI peripheral.
void SPI_DeInit (SPI_TypeDef *SPIx)
 Deinitializes the SPI peripheral registers to their default reset values.
void SPI_DMACmd (SPI_TypeDef *SPIx, SPI_DMAReq_TypeDef SPI_DMAReq, FunctionalState NewState)
 Enables or disables the SPI DMA interface.
uint8_t SPI_GetCRC (SPI_TypeDef *SPIx, SPI_CRC_TypeDef SPI_CRC)
 Returns the transmit or the receive CRC register value.
uint8_t SPI_GetCRCPolynomial (SPI_TypeDef *SPIx)
 Returns the CRC Polynomial register value.
FlagStatus SPI_GetFlagStatus (SPI_TypeDef *SPIx, SPI_FLAG_TypeDef SPI_FLAG)
 Checks whether the specified SPI flag is set or not.
ITStatus SPI_GetITStatus (SPI_TypeDef *SPIx, SPI_IT_TypeDef SPI_IT)
 Checks whether the specified interrupt has occurred or not.
void SPI_Init (SPI_TypeDef *SPIx, SPI_FirstBit_TypeDef SPI_FirstBit, SPI_BaudRatePrescaler_TypeDef SPI_BaudRatePrescaler, SPI_Mode_TypeDef SPI_Mode, SPI_CPOL_TypeDef SPI_CPOL, SPI_CPHA_TypeDef SPI_CPHA, SPI_DirectionMode_TypeDef SPI_Data_Direction, SPI_NSS_TypeDef SPI_Slave_Management, uint8_t CRCPolynomial)
 Initializes the SPI according to the specified parameters.
void SPI_ITConfig (SPI_TypeDef *SPIx, SPI_IT_TypeDef SPI_IT, FunctionalState NewState)
 Enables or disables the specified interrupts.
void SPI_NSSInternalSoftwareCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Configures internally by software the NSS pin.
uint8_t SPI_ReceiveData (SPI_TypeDef *SPIx)
 Returns the most recent received data by the SPI peripheral.
void SPI_ResetCRC (SPI_TypeDef *SPIx)
 Reset the Rx CRCR and Tx CRCR registers.
void SPI_SendData (SPI_TypeDef *SPIx, uint8_t Data)
 Transmits a Data through the SPI peripheral.
void SPI_TransmitCRC (SPI_TypeDef *SPIx)
 Enables the transmit of the CRC value.

Detailed Description

SPI driver modules.


Function Documentation

void SPI_BiDirectionalLineConfig ( SPI_TypeDef SPIx,
SPI_Direction_TypeDef  SPI_Direction 
)

Selects the data transfer direction in Bi-directional mode.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_DirectionSpecifies the data transfer direction in Bi-directional mode. This parameter can be one of the following values:
  • SPI_Direction_Rx: Select Rx receive direction in bi-directional mode
  • SPI_Direction_Tx: Select Tx transmission direction in bi-directional mode
Return values:
None

Definition at line 265 of file stm8l15x_spi.c.

References SPI_struct::CR2, IS_SPI_DIRECTION, SPI_CR2_BDOE, and SPI_Direction_Rx.

void SPI_CalculateCRCCmd ( SPI_TypeDef SPIx,
FunctionalState  NewState 
)

Enables or disables the CRC value calculation of the transferred bytes.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
NewStateIndicates the new state of the SPI CRC value calculation. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 420 of file stm8l15x_spi.c.

References SPI_struct::CR2, DISABLE, IS_FUNCTIONAL_STATE, SPI1, SPI_Cmd(), and SPI_CR2_CRCEN.

Referenced by SPI_ResetCRC().

void SPI_ClearFlag ( SPI_TypeDef SPIx,
SPI_FLAG_TypeDef  SPI_FLAG 
)

Clears the SPI flags.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_FLAG,:Specifies the flag to clear. This parameter can be one of the following values:
  • SPI_FLAG_CRCERR
  • SPI_FLAG_WKUP
Note:
OVR (OverRun Error) interrupt pending bit is cleared by software sequence: a read operation to SPI_DR register (SPI_ReceiveData()) followed by a read operation to SPI_SR register (SPI_GetFlagStatus()).
MODF (Mode Fault) interrupt pending bit is cleared by software sequence: a read/write operation to SPI_SR register (SPI_GetFlagStatus()) followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
Return values:
None

Definition at line 690 of file stm8l15x_spi.c.

References IS_SPI_CLEAR_FLAG, and SPI_struct::SR.

void SPI_ClearITPendingBit ( SPI_TypeDef SPIx,
SPI_IT_TypeDef  SPI_IT 
)

Clears the interrupt pending bits.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_IT,:Specifies the interrupt pending bit to clear. This parameter can be one of the following values:
  • SPI_IT_CRCERR
  • SPI_IT_WKUP
Note:
OVR (OverRun Error) interrupt pending bit is cleared by software sequence: a read operation to SPI_DR register (SPI_ReceiveData()) followed by a read operation to SPI_SR register (SPI_GetITStatus()).
MODF (Mode Fault) interrupt pending bit is cleared by software sequence: a read/write operation to SPI_SR register (SPI_GetITStatus()) followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
Return values:
None

Definition at line 758 of file stm8l15x_spi.c.

References IS_SPI_CLEAR_IT, and SPI_struct::SR.

void SPI_Cmd ( SPI_TypeDef SPIx,
FunctionalState  NewState 
)

Enables or disables the SPI peripheral.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
NewStateNew state of the SPI peripheral. This parameter can be: ENABLE or DISABLE
Return values:
None

Definition at line 219 of file stm8l15x_spi.c.

References SPI_struct::CR1, DISABLE, IS_FUNCTIONAL_STATE, and SPI_CR1_SPE.

Referenced by SPI_CalculateCRCCmd(), and SPI_ResetCRC().

void SPI_DeInit ( SPI_TypeDef SPIx)

Deinitializes the SPI peripheral registers to their default reset values.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
None
Return values:
None

Definition at line 122 of file stm8l15x_spi.c.

References SPI_struct::CR1, SPI_struct::CR2, SPI_struct::CR3, SPI_struct::CRCPR, SPI_CR1_RESET_VALUE, SPI_CR2_RESET_VALUE, SPI_CR3_RESET_VALUE, SPI_CRCPR_RESET_VALUE, SPI_SR_RESET_VALUE, and SPI_struct::SR.

void SPI_DMACmd ( SPI_TypeDef SPIx,
SPI_DMAReq_TypeDef  SPI_DMAReq,
FunctionalState  NewState 
)

Enables or disables the SPI DMA interface.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_DMAReqSpecifies the SPI DMA transfer request to be enabled or disabled. This parameter can be one of the following values:
  • SPI_DMAReq_RX: SPI DMA Rx transfer requests
  • SPI_DMAReq_TX: SPI DMA Tx transfer requests
NewStateIndicates the new state of the SPI DMA request. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 519 of file stm8l15x_spi.c.

References SPI_struct::CR3, DISABLE, IS_FUNCTIONAL_STATE, and IS_SPI_DMAREQ.

uint8_t SPI_GetCRC ( SPI_TypeDef SPIx,
SPI_CRC_TypeDef  SPI_CRC 
)

Returns the transmit or the receive CRC register value.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_CRC,:Specifies the CRC register to be read. This parameter can be one of the following values:
  • SPI_CRC_RX: Select Tx CRC register
  • SPI_CRC_TX: Select Rx CRC register
Return values:
Theselected CRC register value.

Definition at line 447 of file stm8l15x_spi.c.

References IS_SPI_CRC, SPI_struct::RXCRCR, SPI_CRC_RX, and SPI_struct::TXCRCR.

uint8_t SPI_GetCRCPolynomial ( SPI_TypeDef SPIx)

Returns the CRC Polynomial register value.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
Return values:
uint8_tThe CRC Polynomial register value.

Definition at line 487 of file stm8l15x_spi.c.

References SPI_struct::CRCPR.

FlagStatus SPI_GetFlagStatus ( SPI_TypeDef SPIx,
SPI_FLAG_TypeDef  SPI_FLAG 
)

Checks whether the specified SPI flag is set or not.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_FLAG,:Specifies the flag to check. This parameter can be one of the following values:
  • SPI_FLAG_BSY: Busy
  • SPI_FLAG_OVR: Overrun
  • SPI_FLAG_MODF: Mode fault
  • SPI_FLAG_CRCERR: CRC error
  • SPI_FLAG_WKUP: Wake-up
  • SPI_FLAG_TXE: Transmit buffer empty
  • SPI_FLAG_RXNE: Receive buffer empty
Return values:
Indicatesthe state of SPI_FLAG. This parameter can be SET or RESET.

Definition at line 655 of file stm8l15x_spi.c.

References IS_SPI_FLAG, RESET, SET, and SPI_struct::SR.

ITStatus SPI_GetITStatus ( SPI_TypeDef SPIx,
SPI_IT_TypeDef  SPI_IT 
)

Checks whether the specified interrupt has occurred or not.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_IT,:Specifies the SPI interrupt pending bit to check. This parameter can be one of the following values:
  • SPI_IT_CRCERR
  • SPI_IT_WKUP
  • SPI_IT_OVR
  • SPI_IT_MODF
  • SPI_IT_RXNE
  • SPI_IT_TXE
Return values:
Indicatesthe state of the SPI_IT.

Definition at line 711 of file stm8l15x_spi.c.

References __IO, SPI_struct::CR3, IS_SPI_GET_IT, RESET, SET, and SPI_struct::SR.

void SPI_Init ( SPI_TypeDef SPIx,
SPI_FirstBit_TypeDef  SPI_FirstBit,
SPI_BaudRatePrescaler_TypeDef  SPI_BaudRatePrescaler,
SPI_Mode_TypeDef  SPI_Mode,
SPI_CPOL_TypeDef  SPI_CPOL,
SPI_CPHA_TypeDef  SPI_CPHA,
SPI_DirectionMode_TypeDef  SPI_Data_Direction,
SPI_NSS_TypeDef  SPI_Slave_Management,
uint8_t  CRCPolynomial 
)

Initializes the SPI according to the specified parameters.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_FirstBit,:This parameter can be any of the This parameter can be one of the following values:
  • SPI_FirstBit_MSB: MSB bit will be transmitted first
  • SPI_FirstBit_LSB: LSB bit will be transmitted first
SPI_BaudRatePrescaler,:This parameter can be any of the This parameter can be one of the following values:
  • SPI_BaudRatePrescaler_2: SPI frequency = frequency(CPU)/2
  • SPI_BaudRatePrescaler_4: SPI frequency = frequency(CPU)/4
  • SPI_BaudRatePrescaler_8: SPI frequency = frequency(CPU)/8
  • SPI_BaudRatePrescaler_16: SPI frequency = frequency(CPU)/16
  • SPI_BaudRatePrescaler_32: SPI frequency = frequency(CPU)/32
  • SPI_BaudRatePrescaler_64: SPI frequency = frequency(CPU)/64
  • SPI_BaudRatePrescaler_128: SPI frequency = frequency(CPU)/128
  • SPI_BaudRatePrescaler_256: SPI frequency = frequency(CPU)/256
SPI_Mode,:Mode This parameter can be one of the following values:
  • SPI_Mode_Master: SPI Master configuration
  • SPI_Mode_Slave: SPI Slave configuration
SPI_CPOL,:Clock Polarity This parameter can be one of the following values:
  • SPI_CPOL_Low: Clock to 0 when idle
  • SPI_CPOL_High: Clock to 1 when idle
SPI_CPHA,:Clock Phase This parameter can be one of the following values:
  • SPI_CPHA_1Edge: The first clock transition is the first data capture edge
  • SPI_CPHA_2Edge: The second clock transition is the first data capture edge
SPI_Data_Direction,:Data direction This parameter can be one of the following values:
  • SPI_Direction_Rx: Select Rx receive direction in bi-directional mode
  • SPI_Direction_Tx: Select Tx transmission direction in bi-directional mode
SPI_Slave_Management,:Slave management This parameter can be one of the following values:
  • SPI_NSS_Soft: Software slave management disabled
  • SPI_NSS_Hard: Software slave management enabled
CRCPolynomial,:Configures the CRC polynomial.
Return values:
None

Definition at line 171 of file stm8l15x_spi.c.

References SPI_struct::CR1, SPI_struct::CR2, SPI_struct::CRCPR, IS_SPI_BAUDRATE_PRESCALER, IS_SPI_CRC_POLYNOMIAL, IS_SPI_DATA_DIRECTION, IS_SPI_FIRSTBIT, IS_SPI_MODE, IS_SPI_PHASE, IS_SPI_POLARITY, IS_SPI_SLAVEMANAGEMENT, SPI_CR2_SSI, and SPI_Mode_Master.

void SPI_ITConfig ( SPI_TypeDef SPIx,
SPI_IT_TypeDef  SPI_IT,
FunctionalState  NewState 
)

Enables or disables the specified interrupts.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
SPI_ITSpecifies the SPI interrupts sources to be enabled or disabled. This parameter can be one of the following values:
  • SPI_IT_TXE: Transmit buffer empty
  • SPI_IT_RXNE: Receive buffer not empty
  • SPI_IT_ERR: Error
  • SPI_IT_WKUP: Wake-up
NewState,:The new state of the specified SPI interrupts. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 620 of file stm8l15x_spi.c.

References SPI_struct::CR3, DISABLE, IS_FUNCTIONAL_STATE, and IS_SPI_CONFIG_IT.

void SPI_NSSInternalSoftwareCmd ( SPI_TypeDef SPIx,
FunctionalState  NewState 
)

Configures internally by software the NSS pin.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
NewStateIndicates the new state of the SPI Software slave management. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 241 of file stm8l15x_spi.c.

References SPI_struct::CR2, DISABLE, IS_FUNCTIONAL_STATE, and SPI_CR2_SSI.

uint8_t SPI_ReceiveData ( SPI_TypeDef SPIx)

Returns the most recent received data by the SPI peripheral.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
Return values:
Thevalue of the received data.

Definition at line 323 of file stm8l15x_spi.c.

References SPI_struct::DR.

void SPI_ResetCRC ( SPI_TypeDef SPIx)

Reset the Rx CRCR and Tx CRCR registers.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
Return values:
None

Definition at line 472 of file stm8l15x_spi.c.

References ENABLE, SPI_CalculateCRCCmd(), and SPI_Cmd().

void SPI_SendData ( SPI_TypeDef SPIx,
uint8_t  Data 
)

Transmits a Data through the SPI peripheral.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
Data,:Byte to be transmitted.
Return values:
None

Definition at line 313 of file stm8l15x_spi.c.

References SPI_struct::DR.

void SPI_TransmitCRC ( SPI_TypeDef SPIx)

Enables the transmit of the CRC value.

Parameters:
SPIx,:where x can be 1 to select the specified SPI peripheral.
Return values:
None

Definition at line 408 of file stm8l15x_spi.c.

References SPI_struct::CR2, and SPI_CR2_CRCNEXT.

STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com