EasyManuals Logo

STMicroelectronics STM8 User Manual

STMicroelectronics STM8
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #102 background imageLoading...
Page #102 background image
{
UART1_DeInit();
UART1_Init(9600,
UART1_WORDLENGTH_8D,
UART1_STOPBITS_1,
UART1_PARITY_NO,
UART1_SYNCMODE_CLOCK_DISABLE,
UART1_MODE_TXRX_ENABLE);
UART1_Cmd(ENABLE);
}
Explanation
The peripheral and CPU clocks are set at 2MHz:
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
….
….
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
The TX-RX GPIO pins are set as output and input respectively:
GPIO_DeInit(GPIOD);
GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_PU_NO_IT);
UART setup is straightforward. We just need to set baud rate, no. of data bits, no. of stop bit, parity
and type of communication (synchronous or asynchronous).
void UART1_setup(void)
{
UART1_DeInit();
UART1_Init(9600,
UART1_WORDLENGTH_8D,
UART1_STOPBITS_1,
UART1_PARITY_NO,
UART1_SYNCMODE_CLOCK_DISABLE,
UART1_MODE_TXRX_ENABLE);
UART1_Cmd(ENABLE);
}
In the main code, we are checking both transmission complete and reception complete flags. With
these flags, we will know if new data arrived and if it is possible to send a new data.
The first part checks if any new data received. That’s why the IF condition is checking if the RX buffer
is empty or not. If it is not empty then new data must have arrived. The new data (a character here) is
fetched and displayed on a LCD. Then we clear the RX buffer not empty flag to enable reception of
new data. After that we are sending some data to the host PC over the UART.
if(UART1_GetFlagStatus(UART1_FLAG_RXNE) == TRUE)
{

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the STMicroelectronics STM8 and is the answer not in the manual?

STMicroelectronics STM8 Specifications

General IconGeneral
BrandSTMicroelectronics
ModelSTM8
CategoryMicrocontrollers
LanguageEnglish

Related product manuals