STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/USART/USART_HyperTerminalInterrupt/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file USART/USART_HyperTerminalInterrupt/main.c 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Main program body 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "main.h" 00030 00031 /** @addtogroup STM32F0xx_StdPeriph_Examples 00032 * @{ 00033 */ 00034 00035 /** @addtogroup HyperTerminal_Interrupt 00036 * @{ 00037 */ 00038 00039 /* Private typedef -----------------------------------------------------------*/ 00040 /* Private define ------------------------------------------------------------*/ 00041 /* Private macro -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 extern uint8_t NbrOfDataToTransfer; 00044 extern uint8_t NbrOfDataToRead; 00045 extern __IO uint8_t TxCount; 00046 extern __IO uint16_t RxCount; 00047 00048 /* Private function prototypes -----------------------------------------------*/ 00049 static void USART_Config(void); 00050 static void NVIC_Config(void); 00051 00052 00053 /* Private functions ---------------------------------------------------------*/ 00054 00055 /** 00056 * @brief Main program. 00057 * @param None 00058 * @retval None 00059 */ 00060 int main(void) 00061 { 00062 /*!< At this stage the microcontroller clock setting is already configured, 00063 this is done through SystemInit() function which is called from startup 00064 file (startup_stm32f0xx.s) before to branch to application main. 00065 To reconfigure the default setting of SystemInit() function, refer to 00066 system_stm32f0xx.c file 00067 */ 00068 00069 /* NVIC configuration */ 00070 NVIC_Config(); 00071 00072 /* USART configuration */ 00073 USART_Config(); 00074 00075 /* Enable the EVAL_COM1 Transmoit interrupt: this interrupt is generated when the 00076 EVAL_COM1 transmit data register is empty */ 00077 USART_ITConfig(EVAL_COM1, USART_IT_TXE, ENABLE); 00078 00079 /* Wait until EVAL_COM1 send the TxBuffer */ 00080 while(TxCount < NbrOfDataToTransfer) 00081 {} 00082 00083 /* The software must wait until TC=1. The TC flag remains cleared during all data 00084 transfers and it is set by hardware at the last frame�s end of transmission*/ 00085 while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) 00086 {} 00087 00088 /* Enable the EVAL_COM1 Receive interrupt: this interrupt is generated when the 00089 EVAL_COM1 receive data register is not empty */ 00090 USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); 00091 00092 /* Wait until EVAL_COM1 receive the RxBuffer */ 00093 while(RxCount < NbrOfDataToRead) 00094 {} 00095 00096 /* Infinite loop */ 00097 while (1) 00098 { 00099 } 00100 } 00101 00102 /** 00103 * @brief Configures the nested vectored interrupt controller. 00104 * @param None 00105 * @retval None 00106 */ 00107 static void NVIC_Config(void) 00108 { 00109 NVIC_InitTypeDef NVIC_InitStructure; 00110 00111 /* Enable the USART Interrupt */ 00112 NVIC_InitStructure.NVIC_IRQChannel = EVAL_COM1_IRQn; 00113 NVIC_InitStructure.NVIC_IRQChannelPriority = 0; 00114 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 00115 NVIC_Init(&NVIC_InitStructure); 00116 } 00117 00118 /** 00119 * @brief Configure the USART Device 00120 * @param None 00121 * @retval None 00122 */ 00123 static void USART_Config(void) 00124 { 00125 USART_InitTypeDef USART_InitStructure; 00126 00127 /* USARTx configured as follow: 00128 - BaudRate = 9600 baud 00129 - Word Length = 8 Bits 00130 - Two Stop Bit 00131 - Odd parity 00132 - Hardware flow control disabled (RTS and CTS signals) 00133 - Receive and transmit enabled 00134 */ 00135 USART_InitStructure.USART_BaudRate = 9600; 00136 USART_InitStructure.USART_WordLength = USART_WordLength_8b; 00137 USART_InitStructure.USART_StopBits = USART_StopBits_2; 00138 USART_InitStructure.USART_Parity = USART_Parity_Odd; 00139 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 00140 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 00141 00142 STM_EVAL_COMInit(COM1, &USART_InitStructure); 00143 } 00144 00145 #ifdef USE_FULL_ASSERT 00146 00147 /** 00148 * @brief Reports the name of the source file and the source line number 00149 * where the assert_param error has occurred. 00150 * @param file: pointer to the source file name 00151 * @param line: assert_param error line source number 00152 * @retval None 00153 */ 00154 void assert_failed(uint8_t* file, uint32_t line) 00155 { 00156 /* User can add his own implementation to report the file name and line number, 00157 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00158 00159 /* Infinite loop */ 00160 while (1) 00161 { 00162 } 00163 } 00164 #endif 00165 00166 /** 00167 * @} 00168 */ 00169 00170 /** 00171 * @} 00172 */ 00173 00174 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/