Advertisement
Guest User

Untitled

a guest
Jun 15th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.83 KB | None | 0 0
  1. void IRQ_Configure_PF0(void){
  2.     /* Variables */
  3.     GPIO_InitTypeDef GPIO_InitStruct;
  4.     EXTI_InitTypeDef EXTI_InitStruct;
  5.     NVIC_InitTypeDef NVIC_InitStruct;
  6.     /* Enable clock for GPIOF */
  7.     RCC_AHB1PeriphClockCmd(IRQ_GPIO_CLK, ENABLE);
  8.     /* Enable clock for SYSCFG */
  9.     RCC_APB2PeriphClockCmd(SYSCFG_CLK, ENABLE);
  10.     /* GPIO Config */
  11.     GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; // Input Mode
  12.         GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // Push Pull
  13.     GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; // Pin PF0
  14.     GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // UP
  15.     GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
  16.     GPIO_Init(IRQ_GPIO_PORT, &GPIO_InitStruct);
  17.     /* EXTI Config */
  18.     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF, EXTI_PinSource0); // Tell system that it will use PF0 for EXTI_Line0
  19.     EXTI_InitStruct.EXTI_Line = EXTI_Line0; // PF0 is connected to EXTI_Line0
  20.     EXTI_InitStruct.EXTI_LineCmd = ENABLE; // Enable interrupt
  21.     EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; // Interrupt mode
  22.     EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising; // Triggers on rising
  23.     EXTI_Init(&EXTI_InitStruct); // Add to EXTI
  24.     /* Add IRQ vector to NVIC */
  25.     NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn; // PF0 is connected to EXTI_Line0, which has EXTI0_IRQn vector
  26.     NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00; // Set priority
  27.     NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00; // Set sub priority
  28.     NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; // Enable interrupt
  29.     NVIC_Init(&NVIC_InitStruct); // Add to NVIC
  30. }
  31. void EXTI0_IRQHandler(void){
  32.     if (EXTI_GetITStatus(EXTI_Line0) != RESET) // Make sure that interrupt flag is set
  33.         {
  34.             uint8_t mainreg;
  35.             mainreg = AS3911B_Read_Register(AS3911B_MAIN_IT); // Looking for IT Source, we have to read the 3 IT registers in 1 attempt
  36.             if((mainreg & 0x01) == 0x01) // IRQ due to error and wake-up timer
  37.             {
  38.                 uint8_t auxreg1 = AS3911B_Read_Register(AS3911B_ERROR_WAKEUP_IT); // Reading Auxiliary IT Register 2
  39.                 if (auxreg1 & 0x80) {} // CRC Error
  40.                 else if (auxreg1 & 0x40) {}// Parity error
  41.                 else if (auxreg1 & 0x20) {}// Soft framing error
  42.                 else if (auxreg1 & 0x10) {}// Hard framing error
  43.                 else if (auxreg1 & 0x08) {}// Wake-up interrupt
  44.                 else if (auxreg1 & 0x04) {}// Wake-up interrupt due to Amplitude Measurement
  45.                 else if (auxreg1 & 0x02) {}// Wake-up interrupt due to Phase Measurement
  46.                 else if (auxreg1 & 0x01) // Wake-up interrupt due to Capacitance Measurement
  47.                 {
  48.                     //cardPresent=1
  49.                     AS3911B_Enter_Ready_Mode();
  50.         }  
  51.             }
  52.             else if((mainreg & 0x02) == 0x02) // IRQ due to timer or NFC event
  53.             {
  54.                 uint8_t auxreg2 = AS3911B_Read_Register(AS3911B_TIMER_NFC_IT);
  55.                 if (auxreg2 & 0x80) {TM_DISCO_LedOn(LED_GREEN);} // Termination of Direct Command
  56.                 else if (auxreg2 & 0x40) {}// No-response Timer expire
  57.                 else if (auxreg2 & 0x20) {}// GP Timer expire
  58.                 else if (auxreg2 & 0x10) {}// External field greater than target activation level
  59.                 else if (auxreg2 & 0x08) {}// External field less than target activation level
  60.                 else if (auxreg2 & 0x04) {}// Collision detected during RF Collision avoidance
  61.                 else if (auxreg2 & 0x02) {}// Minimum guard time expire
  62.                 else if (auxreg2 & 0x01) {}// Initiator bitrate recognized
  63.             }
  64.             else if((mainreg & 0x04) == 0x04) // IRQ due to bit collision
  65.             {
  66.             }
  67.             else if((mainreg & 0x08) == 0x08) // IRQ due to end of transmission
  68.             {
  69.             }
  70.             else if((mainreg & 0x10) == 0x10) // IRQ due to end of receive
  71.             {
  72.             }
  73.             else if((mainreg & 0x20) == 0x20) // IRQ due to start of receive
  74.             {
  75.             }
  76.             else if((mainreg & 0x40) == 0x40) // IRQ due to FIFO water level
  77.             {
  78.             }
  79.             else if((mainreg & 0x80) == 0x80) // IRQ when oscillator frequency is stable
  80.             {
  81.             }
  82.       EXTI_ClearITPendingBit(EXTI_Line0); // Clear interrupt flag
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement