STM8L15x Standard Peripherals Drivers: Initialization and Configuration functions

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

Initialization and Configuration functions

Initialization and Configuration functions. More...

Functions

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_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_SendBreak (USART_TypeDef *USARTx)
 Transmits break characters.
void USART_SetPrescaler (USART_TypeDef *USARTx, uint8_t USART_Prescaler)
 Sets the system clock prescaler.

Detailed Description

Initialization and Configuration functions.

 ===============================================================================
                  Initialization and Configuration functions
 ===============================================================================  

  This subsection provides a set of functions allowing to initialize the USART 
  in asynchronous and in synchronous modes.
   - For the asynchronous mode only these parameters can be configured: 
        - Baud Rate
        - Word Length 
        - Stop Bit
        - Parity: If the parity is enabled, then the MSB bit of the data written
          in the data register is transmitted but is changed by the parity bit.
          Depending on the frame length defined by the M bit (8-bits or 9-bits),
          the possible USART frame formats are as listed in the following table:
   +-------------------------------------------------------------+     
   |   M bit |  PCE bit  |            USART frame                |
   |---------------------|---------------------------------------|             
   |    0    |    0      |    | SB | 8 bit data | STB |          |
   |---------|-----------|---------------------------------------|  
   |    0    |    1      |    | SB | 7 bit data | PB | STB |     |
   |---------|-----------|---------------------------------------|  
   |    1    |    0      |    | SB | 9 bit data | STB |          |
   |---------|-----------|---------------------------------------|  
   |    1    |    1      |    | SB | 8 bit data | PB | STB |     |
   +-------------------------------------------------------------+            
        - Receiver/transmitter modes

  The USART_Init() function follows the USART  asynchronous configuration procedure
  (details for the procedure are available in reference manual (RM0031)).

  - For the synchronous mode in addition to the asynchronous mode parameters these 
    parameters should be also configured:
        - USART Clock Enabled
        - USART polarity
        - USART phase
        - USART LastBit
  
  These parameters can be configured using the USART_ClockInit() function.


Function Documentation

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_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_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_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.

STM8S Firmware Library: Overview

 

 

 

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