STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/I2C/I2C_TwoBoards/I2C_DataExchange/Slave/stm8s_it.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm8s_it.c 00004 * @author MCD Application Team 00005 * @version V2.2.0 00006 * @date 30-September-2014 00007 * @brief Main Interrupt Service Routines. 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 "stm8s_it.h" 00030 #include "stm8s_eval.h" 00031 #include "main.h" 00032 /** @addtogroup I2C_TwoBoards 00033 * @{ 00034 */ 00035 00036 /** @addtogroup I2C_DataExchange 00037 * @{ 00038 */ 00039 /* Private typedef -----------------------------------------------------------*/ 00040 /* Private define ------------------------------------------------------------*/ 00041 /* Private macro -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 __IO uint8_t Slave_Buffer_Rx[255]; 00044 __IO uint8_t Tx_Idx = 0, Rx_Idx = 0; 00045 __IO uint16_t Event = 0x00; 00046 /* Private function prototypes -----------------------------------------------*/ 00047 /* Private functions ---------------------------------------------------------*/ 00048 /* Public functions ----------------------------------------------------------*/ 00049 00050 #ifdef _COSMIC_ 00051 /** 00052 * @brief Dummy interrupt routine 00053 * @param None 00054 * @retval None 00055 */ 00056 @far @interrupt void NonHandledInterrupt(void) 00057 { 00058 /* In order to detect unexpected events during development, 00059 it is recommended to set a breakpoint on the following instruction. 00060 */ 00061 } 00062 00063 /** 00064 * @brief TRAP interrupt routine 00065 * @param None 00066 * @retval None 00067 */ 00068 @far @interrupt void TRAP_IRQHandler(void) 00069 { 00070 /* In order to detect unexpected events during development, 00071 it is recommended to set a breakpoint on the following instruction. 00072 */ 00073 } 00074 #else /*_RAISONANCE_*/ 00075 00076 /** 00077 * @brief TRAP interrupt routine 00078 * @param None 00079 * @retval None 00080 */ 00081 INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler) 00082 { 00083 /* In order to detect unexpected events during development, 00084 it is recommended to set a breakpoint on the following instruction. 00085 */ 00086 } 00087 #endif /*_COSMIC_*/ 00088 00089 /** 00090 * @brief Top Level Interrupt routine 00091 * @param None 00092 * @retval 00093 * None 00094 */ 00095 INTERRUPT_HANDLER(TLI_IRQHandler, 0) 00096 { 00097 /* In order to detect unexpected events during development, 00098 it is recommended to set a breakpoint on the following instruction. 00099 */ 00100 } 00101 00102 /** 00103 * @brief Auto Wake Up Interrupt routine 00104 * @param None 00105 * @retval 00106 * None 00107 */ 00108 INTERRUPT_HANDLER(AWU_IRQHandler, 1) 00109 { 00110 /* In order to detect unexpected events during development, 00111 it is recommended to set a breakpoint on the following instruction. 00112 */ 00113 } 00114 00115 /** 00116 * @brief Clock Controller Interrupt routine 00117 * @param None 00118 * @retval 00119 * None 00120 */ 00121 INTERRUPT_HANDLER(CLK_IRQHandler, 2) 00122 { 00123 /* In order to detect unexpected events during development, 00124 it is recommended to set a breakpoint on the following instruction. 00125 */ 00126 } 00127 00128 /** 00129 * @brief External Interrupt PORTA Interrupt routine 00130 * @param None 00131 * @retval 00132 * None 00133 */ 00134 INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3) 00135 { 00136 /* In order to detect unexpected events during development, 00137 it is recommended to set a breakpoint on the following instruction. 00138 */ 00139 } 00140 00141 /** 00142 * @brief External Interrupt PORTB Interrupt routine 00143 * @param None 00144 * @retval None 00145 */ 00146 INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4) 00147 { 00148 /* In order to detect unexpected events during development, 00149 it is recommended to set a breakpoint on the following instruction. 00150 */ 00151 } 00152 00153 /** 00154 * @brief External Interrupt PORTC Interrupt routine 00155 * @param None 00156 * @retval 00157 * None 00158 */ 00159 INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5) 00160 { 00161 /* In order to detect unexpected events during development, 00162 it is recommended to set a breakpoint on the following instruction. 00163 */ 00164 } 00165 00166 /** 00167 * @brief External Interrupt PORTD Interrupt routine 00168 * @param None 00169 * @retval 00170 * None 00171 */ 00172 INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6) 00173 { 00174 /* In order to detect unexpected events during development, 00175 it is recommended to set a breakpoint on the following instruction. 00176 */ 00177 } 00178 00179 /** 00180 * @brief External Interrupt PORTE Interrupt routine 00181 * @param None 00182 * @retval 00183 * None 00184 */ 00185 INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7) 00186 { 00187 /* In order to detect unexpected events during development, 00188 it is recommended to set a breakpoint on the following instruction. 00189 */ 00190 } 00191 #ifdef STM8S903 00192 /** 00193 * @brief External Interrupt PORTF Interrupt routine 00194 * @param None 00195 * @retval 00196 * None 00197 */ 00198 INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8) 00199 { 00200 /* In order to detect unexpected events during development, 00201 it is recommended to set a breakpoint on the following instruction. 00202 */ 00203 } 00204 #endif /*STM8S903*/ 00205 00206 #ifdef STM8S208 00207 /** 00208 * @brief CAN RX Interrupt routine 00209 * @param None 00210 * @retval 00211 * None 00212 */ 00213 INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8) 00214 { 00215 /* In order to detect unexpected events during development, 00216 it is recommended to set a breakpoint on the following instruction. 00217 */ 00218 } 00219 00220 /** 00221 * @brief CAN TX Interrupt routine 00222 * @param None 00223 * @retval 00224 * None 00225 */ 00226 INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9) 00227 { 00228 /* In order to detect unexpected events during development, 00229 it is recommended to set a breakpoint on the following instruction. 00230 */ 00231 } 00232 #endif /*STM8S208 || STM8AF52Ax */ 00233 00234 /** 00235 * @brief SPI Interrupt routine 00236 * @param None 00237 * @retval 00238 * None 00239 */ 00240 INTERRUPT_HANDLER(SPI_IRQHandler, 10) 00241 { 00242 /* In order to detect unexpected events during development, 00243 it is recommended to set a breakpoint on the following instruction. 00244 */ 00245 } 00246 00247 /** 00248 * @brief Timer1 Update/Overflow/Trigger/Break Interrupt routine 00249 * @param None 00250 * @retval 00251 * None 00252 */ 00253 INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11) 00254 { 00255 /* In order to detect unexpected events during development, 00256 it is recommended to set a breakpoint on the following instruction. 00257 */ 00258 } 00259 00260 /** 00261 * @brief Timer1 Capture/Compare Interrupt routine 00262 * @param None 00263 * @retval 00264 * None 00265 */ 00266 INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12) 00267 { 00268 /* In order to detect unexpected events during development, 00269 it is recommended to set a breakpoint on the following instruction. 00270 */ 00271 } 00272 00273 #ifdef STM8S903 00274 /** 00275 * @brief Timer5 Update/Overflow/Break/Trigger Interrupt routine 00276 * @param None 00277 * @retval 00278 * None 00279 */ 00280 INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13) 00281 { 00282 /* In order to detect unexpected events during development, 00283 it is recommended to set a breakpoint on the following instruction. 00284 */ 00285 } 00286 /** 00287 * @brief Timer5 Capture/Compare Interrupt routine 00288 * @param None 00289 * @retval 00290 * None 00291 */ 00292 INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14) 00293 { 00294 /* In order to detect unexpected events during development, 00295 it is recommended to set a breakpoint on the following instruction. 00296 */ 00297 } 00298 00299 #else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */ 00300 /** 00301 * @brief Timer2 Update/Overflow/Break Interrupt routine 00302 * @param None 00303 * @retval 00304 * None 00305 */ 00306 INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13) 00307 { 00308 /* In order to detect unexpected events during development, 00309 it is recommended to set a breakpoint on the following instruction. 00310 */ 00311 } 00312 00313 /** 00314 * @brief Timer2 Capture/Compare Interrupt routine 00315 * @param None 00316 * @retval 00317 * None 00318 */ 00319 INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14) 00320 { 00321 /* In order to detect unexpected events during development, 00322 it is recommended to set a breakpoint on the following instruction. 00323 */ 00324 } 00325 #endif /*STM8S903*/ 00326 00327 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 00328 defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x) 00329 /** 00330 * @brief Timer3 Update/Overflow/Break Interrupt routine 00331 * @param None 00332 * @retval 00333 * None 00334 */ 00335 INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15) 00336 { 00337 /* In order to detect unexpected events during development, 00338 it is recommended to set a breakpoint on the following instruction. 00339 */ 00340 } 00341 00342 /** 00343 * @brief Timer3 Capture/Compare Interrupt routine 00344 * @param None 00345 * @retval 00346 * None 00347 */ 00348 INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16) 00349 { 00350 /* In order to detect unexpected events during development, 00351 it is recommended to set a breakpoint on the following instruction. 00352 */ 00353 } 00354 #endif /*STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */ 00355 00356 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ 00357 defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903) 00358 /** 00359 * @brief UART1 TX Interrupt routine 00360 * @param None 00361 * @retval 00362 * None 00363 */ 00364 INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17) 00365 { 00366 /* In order to detect unexpected events during development, 00367 it is recommended to set a breakpoint on the following instruction. 00368 */ 00369 } 00370 00371 /** 00372 * @brief UART1 RX Interrupt routine 00373 * @param None 00374 * @retval 00375 * None 00376 */ 00377 INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18) 00378 { 00379 /* In order to detect unexpected events during development, 00380 it is recommended to set a breakpoint on the following instruction. 00381 */ 00382 } 00383 #endif /*STM8S208, STM8S207 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8S903 */ 00384 00385 /** 00386 * @brief I2C Interrupt routine 00387 * @param None 00388 * @retval 00389 * None 00390 */ 00391 INTERRUPT_HANDLER(I2C_IRQHandler, 19) 00392 { 00393 /* Read SR2 register to get I2C error */ 00394 if ((I2C->SR2) != 0) 00395 { 00396 /* Clears SR2 register */ 00397 I2C->SR2 = 0; 00398 00399 /* Set LED2 */ 00400 STM_EVAL_LEDOn(LED2); 00401 00402 } 00403 Event = I2C_GetLastEvent(); 00404 switch (Event) 00405 { 00406 /******* Slave transmitter ******/ 00407 /* check on EV1 */ 00408 case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED: 00409 Tx_Idx = 0; 00410 break; 00411 00412 /* check on EV3 */ 00413 case I2C_EVENT_SLAVE_BYTE_TRANSMITTING: 00414 /* Transmit data */ 00415 I2C_SendData(Slave_Buffer_Rx[Tx_Idx++]); 00416 break; 00417 /******* Slave receiver **********/ 00418 /* check on EV1*/ 00419 case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: 00420 break; 00421 00422 /* Check on EV2*/ 00423 case I2C_EVENT_SLAVE_BYTE_RECEIVED: 00424 Slave_Buffer_Rx[Rx_Idx++] = I2C_ReceiveData(); 00425 break; 00426 00427 /* Check on EV4 */ 00428 case (I2C_EVENT_SLAVE_STOP_DETECTED): 00429 /* write to CR2 to clear STOPF flag */ 00430 I2C->CR2 |= I2C_CR2_ACK; 00431 break; 00432 00433 default: 00434 break; 00435 } 00436 00437 } 00438 00439 #if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x) 00440 /** 00441 * @brief UART2 TX interrupt routine. 00442 * @param None 00443 * @retval 00444 * None 00445 */ 00446 INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20) 00447 { 00448 /* In order to detect unexpected events during development, 00449 it is recommended to set a breakpoint on the following instruction. 00450 */ 00451 } 00452 00453 /** 00454 * @brief UART2 RX interrupt routine. 00455 * @param None 00456 * @retval 00457 * None 00458 */ 00459 INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21) 00460 { 00461 /* In order to detect unexpected events during development, 00462 it is recommended to set a breakpoint on the following instruction. 00463 */ 00464 } 00465 #endif /* STM8S105*/ 00466 00467 #if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 00468 /** 00469 * @brief UART3 TX interrupt routine. 00470 * @param None 00471 * @retval 00472 * None 00473 */ 00474 INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20) 00475 { 00476 /* In order to detect unexpected events during development, 00477 it is recommended to set a breakpoint on the following instruction. 00478 */ 00479 } 00480 00481 /** 00482 * @brief UART3 RX interrupt routine. 00483 * @param None 00484 * @retval 00485 * None 00486 */ 00487 INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21) 00488 { 00489 /* In order to detect unexpected events during development, 00490 it is recommended to set a breakpoint on the following instruction. 00491 */ 00492 } 00493 #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 00494 00495 #if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 00496 /** 00497 * @brief ADC2 interrupt routine. 00498 * @param None 00499 * @retval 00500 * None 00501 */ 00502 INTERRUPT_HANDLER(ADC2_IRQHandler, 22) 00503 { 00504 /* In order to detect unexpected events during development, 00505 it is recommended to set a breakpoint on the following instruction. 00506 */ 00507 } 00508 #else /*STM8S105, STM8S103 or STM8S903 or STM8AF626x */ 00509 /** 00510 * @brief ADC1 interrupt routine. 00511 * @param None 00512 * @retval None 00513 */ 00514 INTERRUPT_HANDLER(ADC1_IRQHandler, 22) 00515 { 00516 /* In order to detect unexpected events during development, 00517 it is recommended to set a breakpoint on the following instruction. 00518 */ 00519 } 00520 #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 00521 00522 #ifdef STM8S903 00523 /** 00524 * @brief Timer6 Update/Overflow/Trigger Interrupt routine 00525 * @param None 00526 * @retval 00527 * None 00528 */ 00529 INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23) 00530 { 00531 /* In order to detect unexpected events during development, 00532 it is recommended to set a breakpoint on the following instruction. 00533 */ 00534 } 00535 #else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */ 00536 /** 00537 * @brief Timer4 Update/Overflow Interrupt routine 00538 * @param None 00539 * @retval 00540 * None 00541 */ 00542 INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23) 00543 { 00544 /* In order to detect unexpected events during development, 00545 it is recommended to set a breakpoint on the following instruction. 00546 */ 00547 } 00548 #endif /*STM8S903*/ 00549 00550 /** 00551 * @brief Eeprom EEC Interrupt routine 00552 * @param None 00553 * @retval 00554 * None 00555 */ 00556 INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24) 00557 { 00558 /* In order to detect unexpected events during development, 00559 it is recommended to set a breakpoint on the following instruction. 00560 */ 00561 } 00562 00563 /** 00564 * @} 00565 */ 00566 00567 00568 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/