STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/USART/USART_TwoBoards/DataExchangeInterrupt/stm32f0xx_it.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file USART/USART_TwoBoards/DataExchangeInterrupt/stm32f0xx_it.c 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Main Interrupt Service Routines. 00008 * This file provides template for all exceptions handler and 00009 * peripherals interrupt service routine. 00010 ****************************************************************************** 00011 * @attention 00012 * 00013 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00014 * 00015 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00016 * You may not use this file except in compliance with the License. 00017 * You may obtain a copy of the License at: 00018 * 00019 * http://www.st.com/software_license_agreement_liberty_v2 00020 * 00021 * Unless required by applicable law or agreed to in writing, software 00022 * distributed under the License is distributed on an "AS IS" BASIS, 00023 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00024 * See the License for the specific language governing permissions and 00025 * limitations under the License. 00026 * 00027 ****************************************************************************** 00028 */ 00029 00030 /* Includes ------------------------------------------------------------------*/ 00031 #include "stm32f0xx_it.h" 00032 00033 00034 /** @addtogroup STM32F0xx_StdPeriph_Examples 00035 * @{ 00036 */ 00037 00038 /** @addtogroup USART_DataExchangeInterrupt 00039 * @{ 00040 */ 00041 00042 /* Private typedef -----------------------------------------------------------*/ 00043 /* Private define ------------------------------------------------------------*/ 00044 /* Private macro -------------------------------------------------------------*/ 00045 /* Private variables ---------------------------------------------------------*/ 00046 extern uint8_t TxBuffer[]; 00047 extern uint8_t RxBuffer[]; 00048 extern uint8_t CmdBuffer[]; 00049 extern uint8_t AckBuffer[]; 00050 extern __IO uint8_t RxIndex; 00051 extern __IO uint8_t TxIndex; 00052 00053 extern __IO uint8_t UsartTransactionType; 00054 extern __IO uint8_t UsartMode; 00055 00056 __IO uint8_t Counter = 0x00; 00057 extern __IO uint32_t TimeOut; 00058 00059 /* Private function prototypes -----------------------------------------------*/ 00060 /* Private functions ---------------------------------------------------------*/ 00061 00062 /******************************************************************************/ 00063 /* Cortex-M0 Processor Exceptions Handlers */ 00064 /******************************************************************************/ 00065 00066 /** 00067 * @brief This function handles NMI exception. 00068 * @param None 00069 * @retval None 00070 */ 00071 void NMI_Handler(void) 00072 { 00073 } 00074 00075 /** 00076 * @brief This function handles Hard Fault exception. 00077 * @param None 00078 * @retval None 00079 */ 00080 void HardFault_Handler(void) 00081 { 00082 /* Go to infinite loop when Hard Fault exception occurs */ 00083 while (1) 00084 { 00085 } 00086 } 00087 00088 /** 00089 * @brief This function handles SVCall exception. 00090 * @param None 00091 * @retval None 00092 */ 00093 void SVC_Handler(void) 00094 { 00095 } 00096 00097 /** 00098 * @brief This function handles PendSVC exception. 00099 * @param None 00100 * @retval None 00101 */ 00102 void PendSV_Handler(void) 00103 { 00104 } 00105 00106 /** 00107 * @brief This function handles SysTick Handler. 00108 * @param None 00109 * @retval None 00110 */ 00111 void SysTick_Handler(void) 00112 { 00113 /* Decrement the timeout value */ 00114 if (TimeOut != 0x0) 00115 { 00116 TimeOut--; 00117 } 00118 00119 if (Counter < 10) 00120 { 00121 Counter++; 00122 } 00123 else 00124 { 00125 Counter = 0x00; 00126 STM_EVAL_LEDToggle(LED1); 00127 } 00128 } 00129 00130 /******************************************************************************/ 00131 /* STM32F0xx Peripherals Interrupt Handlers */ 00132 /******************************************************************************/ 00133 /** 00134 * @brief This function handles USART interrupt request. 00135 * @param None 00136 * @retval None 00137 */ 00138 void USARTx_IRQHandler(void) 00139 { 00140 /* USART in mode Transmitter -------------------------------------------------*/ 00141 if (USART_GetITStatus(USARTx, USART_IT_TXE) == SET) 00142 { /* When Joystick Pressed send the command then send the data */ 00143 if (UsartMode == USART_MODE_TRANSMITTER) 00144 { /* Send the command */ 00145 if (UsartTransactionType == USART_TRANSACTIONTYPE_CMD) 00146 { 00147 USART_SendData(USARTx, CmdBuffer[TxIndex++]); 00148 if (TxIndex == 0x02) 00149 { 00150 /* Disable the USARTx transmit data register empty interrupt */ 00151 USART_ITConfig(USARTx, USART_IT_TXE, DISABLE); 00152 } 00153 } 00154 /* Send the data */ 00155 else 00156 { 00157 USART_SendData(USARTx, TxBuffer[TxIndex++]); 00158 if (TxIndex == GetVar_NbrOfData()) 00159 { 00160 /* Disable the USARTx transmit data register empty interrupt */ 00161 USART_ITConfig(USARTx, USART_IT_TXE, DISABLE); 00162 } 00163 } 00164 } 00165 /*If Data Received send the ACK*/ 00166 else 00167 { 00168 USART_SendData(USARTx, AckBuffer[TxIndex++]); 00169 if (TxIndex == 0x02) 00170 { 00171 /* Disable the USARTx transmit data register empty interrupt */ 00172 USART_ITConfig(USARTx, USART_IT_TXE, DISABLE); 00173 } 00174 } 00175 } 00176 00177 /* USART in mode Receiver --------------------------------------------------*/ 00178 if (USART_GetITStatus(USARTx, USART_IT_RXNE) == SET) 00179 { 00180 if (UsartMode == USART_MODE_TRANSMITTER) 00181 { 00182 AckBuffer[RxIndex++] = USART_ReceiveData(USARTx); 00183 } 00184 else 00185 { 00186 /* Receive the command */ 00187 if (UsartTransactionType == USART_TRANSACTIONTYPE_CMD) 00188 { 00189 CmdBuffer[RxIndex++] = USART_ReceiveData(USARTx); 00190 } 00191 /* Receive the USART data */ 00192 else 00193 { 00194 RxBuffer[RxIndex++] = USART_ReceiveData(USARTx); 00195 } 00196 } 00197 } 00198 } 00199 /******************************************************************************/ 00200 /* STM32F0xx Peripherals Interrupt Handlers */ 00201 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 00202 /* available peripheral interrupt handler's name please refer to the startup */ 00203 /* file (startup_stm32f0xx.s). */ 00204 /******************************************************************************/ 00205 00206 /** 00207 * @brief This function handles PPP interrupt request. 00208 * @param None 00209 * @retval None 00210 */ 00211 /*void PPP_IRQHandler(void) 00212 { 00213 }*/ 00214 00215 /** 00216 * @} 00217 */ 00218 00219 /** 00220 * @} 00221 */ 00222 00223 00224 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/