STM8L15x Standard Peripherals Drivers: USART

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

USART driver modules. More...

Modules

 USART_Exported_Types
 USART_Private_Functions

Functions

void USART_ClearFlag (USART_TypeDef *USARTx, USART_FLAG_TypeDef USART_FLAG)
 Clears the USARTx's pending flags.
void USART_ClearITPendingBit (USART_TypeDef *USARTx, USART_IT_TypeDef USART_IT)
 Clears the USARTx�s interrupt pending bits.
void USART_ClockInit (USART_TypeDef *USARTx, USART_Clock_TypeDef USART_Clock, USART_CPOL_TypeDef USART_CPOL, USART_CPHA_TypeDef USART_CPHA, USART_LastBit_TypeDef USART_LastBit)
 Initializes the USART Clock according to the specified parameters.
void USART_Cmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Enable the USART peripheral.
void USART_DeInit (USART_TypeDef *USARTx)
 Deinitializes the USART peripheral.
void USART_DMACmd (USART_TypeDef *USARTx, USART_DMAReq_TypeDef USART_DMAReq, FunctionalState NewState)
 Enables or disables the USART DMA interface.
FlagStatus USART_GetFlagStatus (USART_TypeDef *USARTx, USART_FLAG_TypeDef USART_FLAG)
 Checks whether the specified USART flag is set or not.
ITStatus USART_GetITStatus (USART_TypeDef *USARTx, USART_IT_TypeDef USART_IT)
 Checks whether the specified USART interrupt has occurred or not.
void USART_HalfDuplexCmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Enables or disables the USART�s Half Duplex communication.
void USART_Init (USART_TypeDef *USARTx, uint32_t BaudRate, USART_WordLength_TypeDef USART_WordLength, USART_StopBits_TypeDef USART_StopBits, USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode)
 Initializes the USART according to the specified parameters.
void USART_IrDACmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Enables or disables the USART�s IrDA interface.
void USART_IrDAConfig (USART_TypeDef *USARTx, USART_IrDAMode_TypeDef USART_IrDAMode)
 Configures the USART�s IrDA interface.
void USART_ITConfig (USART_TypeDef *USARTx, USART_IT_TypeDef USART_IT, FunctionalState NewState)
 Enables or disables the specified USART interrupts.
uint8_t USART_ReceiveData8 (USART_TypeDef *USARTx)
 Returns the most recent received data by the USART peripheral.
uint16_t USART_ReceiveData9 (USART_TypeDef *USARTx)
 Returns the most recent received data by the USART peripheral.
void USART_ReceiverWakeUpCmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Determines if the USART is in mute mode or not.
void USART_SendBreak (USART_TypeDef *USARTx)
 Transmits break characters.
void USART_SendData8 (USART_TypeDef *USARTx, uint8_t Data)
 Transmits 8 bit data through the USART peripheral.
void USART_SendData9 (USART_TypeDef *USARTx, uint16_t Data)
 Transmits 9 bit data through the USART peripheral.
void USART_SetAddress (USART_TypeDef *USARTx, uint8_t USART_Address)
 Sets the address of the USART node.
void USART_SetGuardTime (USART_TypeDef *USARTx, uint8_t USART_GuardTime)
 Sets the specified USART guard time.
void USART_SetPrescaler (USART_TypeDef *USARTx, uint8_t USART_Prescaler)
 Sets the system clock prescaler.
void USART_SmartCardCmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Enables or disables the USART Smart Card mode.
void USART_SmartCardNACKCmd (USART_TypeDef *USARTx, FunctionalState NewState)
 Enables or disables NACK transmission.
void USART_WakeUpConfig (USART_TypeDef *USARTx, USART_WakeUp_TypeDef USART_WakeUp)
 Selects the USART WakeUp method.

#define IS_USART_BAUDRATE(NUM)   ((NUM) <= (uint32_t)625000)
 
#define USART_ADDRESS_MAX   ((uint8_t)16)
#define IS_USART_ADDRESS(address)   ((address) < USART_ADDRESS_MAX)
#define USART_DATA_9BITS_MAX   ((uint16_t)0x1FF)
#define IS_USART_DATA_9BITS(DATA)   ((DATA) < USART_DATA_9BITS_MAX)

Detailed Description

USART driver modules.


Define Documentation

#define IS_USART_ADDRESS (   address)    ((address) < USART_ADDRESS_MAX)

Definition at line 317 of file stm8l15x_usart.h.

Referenced by USART_SetAddress().

#define IS_USART_BAUDRATE (   NUM)    ((NUM) <= (uint32_t)625000)

Definition at line 314 of file stm8l15x_usart.h.

Referenced by USART_Init().

#define IS_USART_DATA_9BITS (   DATA)    ((DATA) < USART_DATA_9BITS_MAX)

Definition at line 320 of file stm8l15x_usart.h.

Referenced by USART_SendData9().

#define USART_ADDRESS_MAX   ((uint8_t)16)

Definition at line 316 of file stm8l15x_usart.h.

#define USART_DATA_9BITS_MAX   ((uint16_t)0x1FF)

Definition at line 319 of file stm8l15x_usart.h.


Function Documentation

void USART_ClearFlag ( USART_TypeDef USARTx,
USART_FLAG_TypeDef  USART_FLAG 
)

Clears the USARTx's pending flags.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_FLAG,:specifies the flag to clear. This parameter can be any combination of the following values:
  • USART_FLAG_TC: Transmission Complete flag.
  • USART_FLAG_RXNE: Receive data register not empty flag.
Note:
PE (Parity error), FE (Framing error), NE (Noise error), OR (OverRun error) and IDLE (Idle line detected) flags are cleared by software sequence: a read operation to USART_SR register (USART_GetFlagStatus())followed by a read operation to USART_DR register(USART_ReceiveData8() or USART_ReceiveData9()).
RXNE flag can be also cleared by a read to the USART_DR register (USART_ReceiveData8()or USART_ReceiveData9()).
TC flag can be also cleared by software sequence: a read operation to USART_SR register (USART_GetFlagStatus()) followed by a write operation to USART_DR register (USART_SendData8() or USART_SendData9()).
TXE flag is cleared only by a write to the USART_DR register (USART_SendData8() or USART_SendData9()).
SBK flag is cleared during the stop bit of break.
Return values:
None

Definition at line 1054 of file stm8l15x_usart.c.

References IS_USART_CLEAR_FLAG, and USART_struct::SR.

void USART_ClearITPendingBit ( USART_TypeDef USARTx,
USART_IT_TypeDef  USART_IT 
)

Clears the USARTx�s interrupt pending bits.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_IT,:specifies the interrupt pending bit to clear. This parameter can be one of the following values:
  • USART_IT_RXNE: Receive Data register not empty interrupt.
  • USART_IT_TC: Transmission complete interrupt.
Note:
PE (Parity error), FE (Framing error), NE (Noise error), OR (OverRun error) and IDLE (Idle line detected) pending bits are cleared by software sequence: a read operation to USART_SR register (USART_GetITStatus()) followed by a read operation to USART_DR register (USART_ReceiveData8() or USART_ReceiveData9()).
RXNE pending bit can be also cleared by a read to the USART_DR register (USART_ReceiveData8() or USART_ReceiveData9()).
TC (Transmit complete) pending bit can be also cleared by software sequence: a read operation to USART_SR register (USART_GetITStatus()) followed by a write operation to USART_DR register (USART_SendData8() or USART_SendData9()).
TXE pending bit is cleared only by a write to the USART_DR register (USART_SendData8() or USART_SendData9()).
Return values:
None

Definition at line 1178 of file stm8l15x_usart.c.

References IS_USART_CLEAR_IT, and USART_struct::SR.

void USART_ClockInit ( USART_TypeDef USARTx,
USART_Clock_TypeDef  USART_Clock,
USART_CPOL_TypeDef  USART_CPOL,
USART_CPHA_TypeDef  USART_CPHA,
USART_LastBit_TypeDef  USART_LastBit 
)

Initializes the USART Clock according to the specified parameters.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_Clock,:Clock This parameter can be one of the following values:
  • USART_Clock_Disable: CK pin disabled
  • USART_Clock_Enable: CK pin enabled
USART_CPOL,:Clock Polarity This parameter can be one of the following values:
  • USART_CPOL_Low: CK to 0 when idle
  • USART_CPOL_High: CK to 1 when idle
USART_CPHA,:Clock Phase This parameter can be one of the following values:
  • USART_CPHA_1Edge: The first clock transition is the first data capture edge
  • USART_CPHA_2Edge: The second clock transition is the first data capture edge
USART_LastBit,:Last Bit This parameter can be one of the following values:
  • USART_LastBit_Disable: The clock pulse of the last data bit is not output to the SCLK pin
  • USART_LastBit_Enable: The clock pulse of the last data bit is output to the SCLK pin
Return values:
None

Definition at line 258 of file stm8l15x_usart.c.

References USART_struct::CR3, IS_USART_CLOCK, IS_USART_CPHA, IS_USART_CPOL, IS_USART_LASTBIT, USART_Clock_Disable, USART_CR3_CLKEN, USART_CR3_CPHA, USART_CR3_CPOL, and USART_CR3_LBCL.

void USART_Cmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Enable the USART peripheral.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
NewState,:The new state of the USART Communication. This parameter can be: ENABLE or DISABLE.
Return values:
None

< USART Enable

< USART Disable (for low power consumption)

Definition at line 290 of file stm8l15x_usart.c.

References USART_struct::CR1, DISABLE, and USART_CR1_USARTD.

void USART_DeInit ( USART_TypeDef USARTx)

Deinitializes the USART peripheral.

Parameters:
USARTx,:where x can be 1, 2 or 3 to select the specified USART peripheral.
Return values:
None

Definition at line 142 of file stm8l15x_usart.c.

References USART_struct::BRR1, USART_struct::BRR2, USART_struct::CR1, USART_struct::CR2, USART_struct::CR3, USART_struct::CR4, USART_struct::DR, USART_struct::SR, USART_BRR1_RESET_VALUE, USART_BRR2_RESET_VALUE, USART_CR1_RESET_VALUE, USART_CR2_RESET_VALUE, USART_CR3_RESET_VALUE, and USART_CR4_RESET_VALUE.

void USART_DMACmd ( USART_TypeDef USARTx,
USART_DMAReq_TypeDef  USART_DMAReq,
FunctionalState  NewState 
)

Enables or disables the USART DMA interface.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_DMAReqSpecifies the USART DMA transfer request to be enabled or disabled. This parameter can be one of the following values:
  • USART_DMAReq_TX: Receive DMA request Enable
  • USART_DMAReq_RX: Transmit DMA request Enable
NewStateIndicates the new state of the USART DMA request. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 812 of file stm8l15x_usart.c.

References USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and IS_USART_DMAREQ.

FlagStatus USART_GetFlagStatus ( USART_TypeDef USARTx,
USART_FLAG_TypeDef  USART_FLAG 
)

Checks whether the specified USART flag is set or not.

Parameters:
USARTx,:Select the USARTx peripheral.
USART_FLAGspecifies the flag to check. This parameter can be one of the following values:
  • USART_FLAG_TXE: Transmit Data Register empty
  • USART_FLAG_TC: Transmission Complete
  • USART_FLAG_RXNE: Read Data Register Not Empty
  • USART_FLAG_IDLE: Idle line detected
  • USART_FLAG_OR: OverRun error
  • USART_FLAG_NF: Noise error
  • USART_FLAG_FE: Framing Error
  • USART_FLAG_PE: Parity Error
  • USART_FLAG_SBK: Send Break characters
Return values:
FlagStatus(SET or RESET)

Definition at line 996 of file stm8l15x_usart.c.

References USART_struct::CR2, IS_USART_FLAG, RESET, SET, USART_struct::SR, and USART_FLAG_SBK.

ITStatus USART_GetITStatus ( USART_TypeDef USARTx,
USART_IT_TypeDef  USART_IT 
)

Checks whether the specified USART interrupt has occurred or not.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_IT,:Specifies the USART interrupt pending bit to check. This parameter can be one of the following values:
  • USART_IT_TXE: Transmit Data Register empty interrupt
  • USART_IT_TC: Transmission complete interrupt
  • USART_IT_RXNE: Receive Data register not empty interrupt
  • USART_IT_IDLE: Idle line detection interrupt
  • USART_IT_OR: OverRun Error interrupt
  • USART_IT_PE: Parity Error interrupt
  • USART_IT_FE: Frame Error interrupt
  • USART_IT_NF: Noise Flag Error interrupt
Return values:
ITStatusThe new state of USART_IT (SET or RESET).

Definition at line 1077 of file stm8l15x_usart.c.

References USART_struct::CR1, USART_struct::CR2, USART_struct::CR5, IS_USART_GET_IT, RESET, SET, USART_struct::SR, USART_CR5_EIE, USART_IT_OR, and USART_IT_PE.

void USART_HalfDuplexCmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Enables or disables the USART�s Half Duplex communication.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
NewStatenew state of the USART Communication. This parameter can be: ENABLE or DISABLE.
Return values:
None

< USART Half Duplex Enable

< USART Half Duplex Disable

Definition at line 560 of file stm8l15x_usart.c.

References USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and USART_CR5_HDSEL.

void USART_Init ( USART_TypeDef USARTx,
uint32_t  BaudRate,
USART_WordLength_TypeDef  USART_WordLength,
USART_StopBits_TypeDef  USART_StopBits,
USART_Parity_TypeDef  USART_Parity,
USART_Mode_TypeDef  USART_Mode 
)

Initializes the USART according to the specified parameters.

Note:
Configure in Push Pull or Open Drain mode the Tx pin by setting the correct I/O Port register according the product package and line configuration
Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
BaudRate,:The baudrate.
USART_WordLength,:the word length This parameter can be one of the following values:
  • USART_WordLength_8b: 8 bits Data
  • USART_WordLength_9b: 9 bits Data
USART_StopBits,:Stop Bit This parameter can be one of the following values:
  • USART_StopBits_1: One stop bit is transmitted at the end of frame
  • USART_StopBits_2: Two stop bits are transmitted at the end of frame
  • USART_StopBits_1_5: One and half stop bits
USART_Parity,:Parity This parameter can be one of the following values:
  • USART_Parity_No: No Parity
  • USART_Parity_Even: Even Parity
  • USART_Parity_Odd: Odd Parity
USART_Mode,:Mode This parameter can be one of the following values:
  • USART_Mode_Rx: Receive Enable
  • USART_Mode_Tx: Transmit Enable
Return values:
None

Definition at line 186 of file stm8l15x_usart.c.

References USART_struct::BRR1, USART_struct::BRR2, CLK_GetClockFreq(), USART_struct::CR1, USART_struct::CR2, USART_struct::CR3, IS_USART_BAUDRATE, IS_USART_MODE, IS_USART_PARITY, IS_USART_STOPBITS, IS_USART_WORDLENGTH, USART_BRR1_DIVM, USART_BRR2_DIVF, USART_BRR2_DIVM, USART_CR1_M, USART_CR1_PCEN, USART_CR1_PS, USART_CR2_REN, USART_CR2_TEN, and USART_CR3_STOP.

void USART_IrDACmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Enables or disables the USART�s IrDA interface.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
NewStatenew state of the IrDA mode. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 766 of file stm8l15x_usart.c.

References USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and USART_CR5_IREN.

void USART_IrDAConfig ( USART_TypeDef USARTx,
USART_IrDAMode_TypeDef  USART_IrDAMode 
)

Configures the USART�s IrDA interface.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_IrDAModespecifies the IrDA mode. This parameter can be one of the following values:
  • USART_IrDAMode_Normal: IrDA Normal Mode
  • USART_IrDAMode_LowPower: IrDA Low Power Mode
Return values:
None

Definition at line 745 of file stm8l15x_usart.c.

References USART_struct::CR5, IS_USART_IRDAMODE, USART_CR5_IRLP, and USART_IrDAMode_Normal.

void USART_ITConfig ( USART_TypeDef USARTx,
USART_IT_TypeDef  USART_IT,
FunctionalState  NewState 
)

Enables or disables the specified USART interrupts.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_ITspecifies the USART interrupt sources to be enabled or disabled. This parameter can be one of the following values:
  • USART_IT_TXE: Transmit Data Register empty interrupt
  • USART_IT_TC: Transmission complete interrupt
  • USART_IT_RXNE: Receive Data register not empty interrupt
  • USART_IT_OR: Overrun error interrupt
  • USART_IT_IDLE: Idle line detection interrupt
  • USART_IT_ERR: Error interrupt
NewStatenew state of the specified USART interrupts. This parameter can be: ENABLE or DISABLE.
Return values:
None

< Enable the Interrupt bits according to USART_IT mask

< Disable the interrupt bits according to USART_IT mask

Definition at line 933 of file stm8l15x_usart.c.

References USART_struct::CR1, USART_struct::CR2, USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and IS_USART_CONFIG_IT.

uint8_t USART_ReceiveData8 ( USART_TypeDef USARTx)

Returns the most recent received data by the USART peripheral.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
Return values:
Thereceived data.

Definition at line 376 of file stm8l15x_usart.c.

References USART_struct::DR.

uint16_t USART_ReceiveData9 ( USART_TypeDef USARTx)

Returns the most recent received data by the USART peripheral.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
Return values:
Thereceived data.

Definition at line 386 of file stm8l15x_usart.c.

References USART_struct::CR1, USART_struct::DR, and USART_CR1_R8.

void USART_ReceiverWakeUpCmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Determines if the USART is in mute mode or not.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
NewState,:The new state of the USART mode. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 467 of file stm8l15x_usart.c.

References USART_struct::CR2, DISABLE, IS_FUNCTIONAL_STATE, and USART_CR2_RWU.

void USART_SendBreak ( USART_TypeDef USARTx)

Transmits break characters.

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

Definition at line 334 of file stm8l15x_usart.c.

References USART_struct::CR2, and USART_CR2_SBK.

void USART_SendData8 ( USART_TypeDef USARTx,
uint8_t  Data 
)

Transmits 8 bit data through the USART peripheral.

Parameters:
Data,:The data to transmit.
Return values:
None

Definition at line 399 of file stm8l15x_usart.c.

References USART_struct::DR.

void USART_SendData9 ( USART_TypeDef USARTx,
uint16_t  Data 
)

Transmits 9 bit data through the USART peripheral.

Parameters:
USARTx,:Select the USARTx peripheral.
Data,:The data to transmit. This parameter should be lower than 0x1FF.
Return values:
None

Definition at line 412 of file stm8l15x_usart.c.

References USART_struct::CR1, USART_struct::DR, IS_USART_DATA_9BITS, and USART_CR1_T8.

void USART_SetAddress ( USART_TypeDef USARTx,
uint8_t  USART_Address 
)

Sets the address of the USART node.

Parameters:
USARTx,:Select the USARTx peripheral.
Address,:Indicates the address of the USART node. This parameter should be lower than 16
Return values:
None

Definition at line 490 of file stm8l15x_usart.c.

References USART_struct::CR4, IS_USART_ADDRESS, and USART_CR4_ADD.

void USART_SetGuardTime ( USART_TypeDef USARTx,
uint8_t  USART_GuardTime 
)

Sets the specified USART guard time.

Note:
SmartCard Mode should be Enabled
Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
USART_GuardTime,:specifies the guard time.
Return values:
None

Definition at line 684 of file stm8l15x_usart.c.

References USART_struct::GTR.

void USART_SetPrescaler ( USART_TypeDef USARTx,
uint8_t  USART_Prescaler 
)

Sets the system clock prescaler.

Note:
IrDA Low Power mode or smartcard mode should be enabled
This function is related to SmartCard and IrDa mode.
Parameters:
USARTx,:Select the USARTx peripheral.
USART_Prescaler,:specifies the prescaler clock.
Note:
In IrDA Low Power Mode the clock source is divided by the value given in the register (8 bits)
  • 0000 0000 Reserved
  • 0000 0001 divides the clock source by 1
  • 0000 0010 divides the clock source by 2
  • ...
In Smart Card Mode the clock source is divided by the value given in the register (5 significant bits) multiplied by 2
  • 0 0000 Reserved
  • 0 0001 divides the clock source by 2
  • 0 0010 divides the clock source by 4
  • 0 0011 divides the clock source by 6
  • ...
Return values:
None

Definition at line 323 of file stm8l15x_usart.c.

References USART_struct::PSCR.

void USART_SmartCardCmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Enables or disables the USART Smart Card mode.

Parameters:
USARTx,:Select the USARTx peripheral.
NewState,:new state of the Smart Card mode. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 638 of file stm8l15x_usart.c.

References USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and USART_CR5_SCEN.

void USART_SmartCardNACKCmd ( USART_TypeDef USARTx,
FunctionalState  NewState 
)

Enables or disables NACK transmission.

Parameters:
USARTx,:where x can be 1 to select the specified USART peripheral.
NewState,:new state of the Smart Card mode. This parameter can be: ENABLE or DISABLE.
Return values:
None

Definition at line 661 of file stm8l15x_usart.c.

References USART_struct::CR5, DISABLE, IS_FUNCTIONAL_STATE, and USART_CR5_NACK.

void USART_WakeUpConfig ( USART_TypeDef USARTx,
USART_WakeUp_TypeDef  USART_WakeUp 
)

Selects the USART WakeUp method.

Parameters:
USART_WakeUp,:Specifies the USART wakeup method. This parameter can be one of the following values:
  • USART_WakeUp_IdleLine: 0x01 Idle Line wake up
  • USART_WakeUp_AddressMark: 0x02 Address Mark wake up
Return values:
None

Definition at line 509 of file stm8l15x_usart.c.

References USART_struct::CR1, IS_USART_WAKEUP, and USART_CR1_WAKE.

STM8S Firmware Library: Overview

 

 

 

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