STM32F0xx Standard Peripherals Firmware Library: stm32f0xx_it.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/SPI/SPI_TwoBoards/DataExchangeInterrupt/stm32f0xx_it.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    SPI/SPI_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>&copy; 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 /** @addtogroup STM32F0xx_StdPeriph_Examples
00034   * @{
00035   */
00036 
00037 /** @addtogroup SPI_DataExchangeInterrupt
00038   * @{
00039   */
00040 
00041 /* Private typedef -----------------------------------------------------------*/
00042 /* Private define ------------------------------------------------------------*/
00043 /* Private macro -------------------------------------------------------------*/
00044 /* Private variables ---------------------------------------------------------*/
00045 extern uint8_t TxBuffer[];
00046 extern  uint8_t RxBuffer[];
00047 extern __IO uint8_t Rx_Idx;
00048 extern __IO uint8_t Tx_Idx;
00049 
00050 extern __IO uint8_t CmdTransmitted;
00051 extern __IO uint8_t CmdReceived;
00052 extern __IO uint8_t CmdStatus;
00053 
00054 __IO uint8_t Counter = 0x00;
00055 extern __IO uint32_t TimeOut;
00056 
00057 /* Private function prototypes -----------------------------------------------*/
00058 /* Private functions ---------------------------------------------------------*/
00059 
00060 /******************************************************************************/
00061 /*            Cortex-M0 Processor Exceptions Handlers                         */
00062 /******************************************************************************/
00063 
00064 /**
00065   * @brief  This function handles NMI exception.
00066   * @param  None
00067   * @retval None
00068   */
00069 void NMI_Handler(void)
00070 {
00071 }
00072 
00073 /**
00074   * @brief  This function handles Hard Fault exception.
00075   * @param  None
00076   * @retval None
00077   */
00078 void HardFault_Handler(void)
00079 {
00080   /* Go to infinite loop when Hard Fault exception occurs */
00081   while (1)
00082   {
00083   }
00084 }
00085 
00086 /**
00087   * @brief  This function handles SVCall exception.
00088   * @param  None
00089   * @retval None
00090   */
00091 void SVC_Handler(void)
00092 {
00093 }
00094 
00095 /**
00096   * @brief  This function handles PendSVC exception.
00097   * @param  None
00098   * @retval None
00099   */
00100 void PendSV_Handler(void)
00101 {
00102 }
00103 
00104 /**
00105   * @brief  This function handles SysTick Handler.
00106   * @param  None
00107   * @retval None
00108   */
00109 void SysTick_Handler(void)
00110 {
00111   /* Decrement the timeout value */
00112   if (TimeOut != 0x0)
00113   {
00114     TimeOut--;
00115   }
00116     
00117   if (Counter < 10)
00118   {
00119     Counter++;
00120   }
00121   else
00122   {
00123     Counter = 0x00;
00124     STM_EVAL_LEDToggle(LED1);
00125   }
00126 }
00127 
00128 /******************************************************************************/
00129 /*            STM32F0xx Peripherals Interrupt Handlers                        */
00130 /******************************************************************************/
00131 /**
00132   * @brief  This function handles SPI interrupt request.
00133   * @param  None
00134   * @retval None
00135   */
00136 void SPI1_IRQHandler(void)
00137 {
00138 #if defined (SPI_SLAVE)  
00139   
00140   /* SPI in Slave Tramitter mode--------------------------------------- */
00141   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_TXE) == SET)
00142   {
00143     SPI_SendData8(SPIx, TxBuffer[Tx_Idx++]);
00144     if (Tx_Idx == GetVar_NbrOfData())
00145     {
00146       /* Disable the Tx buffer empty interrupt */
00147       SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE);
00148     }
00149   }
00150   
00151   /* SPI in Slave Receiver mode--------------------------------------- */
00152   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET)
00153   {
00154     if (CmdReceived == 0x00)
00155     {
00156       CmdReceived = SPI_ReceiveData8(SPIx);
00157       CmdStatus = 0x01;
00158     }
00159     else
00160     {
00161       RxBuffer[Rx_Idx++] = SPI_ReceiveData8(SPIx);
00162     }
00163   }
00164   
00165   /* SPI Error interrupt--------------------------------------- */
00166   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_OVR) == SET)
00167   {
00168     SPI_ReceiveData8(SPIx);
00169     SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_OVR);
00170   }
00171   
00172 #endif /* SPI_SLAVE*/
00173   
00174 #if defined (SPI_MASTER)
00175   
00176   /* SPI in Master Tramitter mode--------------------------------------- */
00177   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_TXE) == SET)
00178   {
00179     if (CmdStatus == 0x00)
00180     {
00181       SPI_SendData8(SPIx, CmdTransmitted);
00182       CmdStatus = 0x01;
00183     }
00184     else
00185     {
00186       SPI_SendData8(SPIx, TxBuffer[Tx_Idx++]);
00187       if (Tx_Idx == GetVar_NbrOfData())
00188       {
00189         /* Disable the Tx buffer empty interrupt */
00190         SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE);
00191       }
00192     }
00193   }
00194   
00195   /* SPI in Master Receiver mode--------------------------------------- */
00196   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET)
00197   {
00198     if (CmdReceived == 0x00)
00199     {
00200       CmdReceived = SPI_ReceiveData8(SPIx);
00201       Rx_Idx = 0x00;
00202     }
00203     else
00204     {
00205       RxBuffer[Rx_Idx++] = SPI_ReceiveData8(SPIx);
00206     }
00207   }
00208   
00209   /* SPI Error interrupt--------------------------------------- */
00210   if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_OVR) == SET)
00211   {
00212     SPI_ReceiveData8(SPIx);
00213     SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_OVR);
00214   }
00215   
00216 #endif /* SPI_MASTER*/
00217 }
00218 /******************************************************************************/
00219 /*                 STM32F0xx Peripherals Interrupt Handlers                   */
00220 /*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
00221 /*  available peripheral interrupt handler's name please refer to the startup */
00222 /*  file (startup_stm32f0xx.s).                                            */
00223 /******************************************************************************/
00224 
00225 /**
00226   * @brief  This function handles PPP interrupt request.
00227   * @param  None
00228   * @retval None
00229   */
00230 /*void PPP_IRQHandler(void)
00231 {
00232 }*/
00233 
00234 /**
00235   * @}
00236   */
00237 
00238 /**
00239   * @}
00240   */ 
00241 
00242 
00243 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32