STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/UART1/UART1_HyperTerminal_Interrupt/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file UART1_HyperTerminal_Interrupt\main.c 00004 * @author MCD Application Team 00005 * @version V2.2.0 00006 * @date 30-September-2014 00007 * @brief This file contains the main function for UART1 using interrupts in 00008 * communication example. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Includes ------------------------------------------------------------------*/ 00030 #include "stm8s.h" 00031 #include "stm8s_eval.h" 00032 00033 /** 00034 * @addtogroup UART1_HyperTerminal_Interrupt 00035 * @{ 00036 */ 00037 /* Private typedef -----------------------------------------------------------*/ 00038 /* Private define ------------------------------------------------------------*/ 00039 /* Private macro -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 /* Private function prototypes -----------------------------------------------*/ 00042 static void GPIO_Config(void); 00043 static void CLK_Config(void); 00044 static void UART1_Config(void); 00045 void Delay(uint32_t nCount); 00046 /* Private functions ---------------------------------------------------------*/ 00047 00048 /** 00049 * @brief Main program. 00050 * @param None 00051 * @retval None 00052 */ 00053 void main(void) 00054 { 00055 /* Clock configuration -----------------------------------------*/ 00056 CLK_Config(); 00057 00058 /* GPIO configuration -----------------------------------------*/ 00059 GPIO_Config(); 00060 00061 /* UART1 configuration -----------------------------------------*/ 00062 UART1_Config(); 00063 00064 00065 while (1) 00066 { 00067 STM_EVAL_LEDToggle(LED1); 00068 STM_EVAL_LEDToggle(LED2); 00069 STM_EVAL_LEDToggle(LED3); 00070 STM_EVAL_LEDToggle(LED4); 00071 Delay((uint32_t)0xFFFF); 00072 } 00073 } 00074 00075 /** 00076 * @brief Configure system clock to run at 16Mhz 00077 * @param None 00078 * @retval None 00079 */ 00080 static void CLK_Config(void) 00081 { 00082 /* Initialization of the clock */ 00083 /* Clock divider to HSI/1 */ 00084 CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); 00085 } 00086 00087 /** 00088 * @brief Configure LEDs available on the evaluation board 00089 * @param None 00090 * @retval None 00091 */ 00092 static void GPIO_Config(void) 00093 { 00094 /* Initialize LEDs mounted on the Eval board */ 00095 STM_EVAL_LEDInit(LED1); 00096 STM_EVAL_LEDInit(LED2); 00097 STM_EVAL_LEDInit(LED3); 00098 STM_EVAL_LEDInit(LED4); 00099 } 00100 00101 /** 00102 * @brief Configure UART1 for the communication with HyperTerminal 00103 * @param None 00104 * @retval None 00105 */ 00106 static void UART1_Config(void) 00107 { 00108 /* EVAL COM (UART) configuration -----------------------------------------*/ 00109 /* USART configured as follow: 00110 - BaudRate = 115200 baud 00111 - Word Length = 8 Bits 00112 - One Stop Bit 00113 - Odd parity 00114 - Receive and transmit enabled 00115 - UART Clock disabled 00116 */ 00117 UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_ODD, 00118 UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); 00119 00120 /* Enable the UART Receive interrupt: this interrupt is generated when the UART 00121 receive data register is not empty */ 00122 UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); 00123 00124 /* Enable the UART Transmit complete interrupt: this interrupt is generated 00125 when the UART transmit Shift Register is empty */ 00126 UART1_ITConfig(UART1_IT_TXE, ENABLE); 00127 00128 /* Enable UART */ 00129 UART1_Cmd(ENABLE); 00130 00131 /* Enable general interrupts */ 00132 enableInterrupts(); 00133 } 00134 00135 /** 00136 * @brief Delay. 00137 * @param nCount 00138 * @retval None 00139 */ 00140 void Delay(uint32_t nCount) 00141 { 00142 /* Decrement nCount value */ 00143 while (nCount != 0) 00144 { 00145 nCount--; 00146 } 00147 } 00148 00149 #ifdef USE_FULL_ASSERT 00150 00151 /** 00152 * @brief Reports the name of the source file and the source line number 00153 * where the assert_param error has occurred. 00154 * @param file: pointer to the source file name 00155 * @param line: assert_param error line source number 00156 * @retval None 00157 */ 00158 void assert_failed(uint8_t* file, uint32_t line) 00159 { 00160 /* User can add his own implementation to report the file name and line number, 00161 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00162 00163 /* Infinite loop */ 00164 while (1) 00165 { 00166 } 00167 } 00168 #endif 00169 00170 /** 00171 * @} 00172 */ 00173 00174 00175 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/