Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void IRQ_Configure_PF0(void){
- /* Variables */
- GPIO_InitTypeDef GPIO_InitStruct;
- EXTI_InitTypeDef EXTI_InitStruct;
- NVIC_InitTypeDef NVIC_InitStruct;
- /* Enable clock for GPIOF */
- RCC_AHB1PeriphClockCmd(IRQ_GPIO_CLK, ENABLE);
- /* Enable clock for SYSCFG */
- RCC_APB2PeriphClockCmd(SYSCFG_CLK, ENABLE);
- /* GPIO Config */
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; // Input Mode
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // Push Pull
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; // Pin PF0
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // UP
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_Init(IRQ_GPIO_PORT, &GPIO_InitStruct);
- /* EXTI Config */
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF, EXTI_PinSource0); // Tell system that it will use PF0 for EXTI_Line0
- EXTI_InitStruct.EXTI_Line = EXTI_Line0; // PF0 is connected to EXTI_Line0
- EXTI_InitStruct.EXTI_LineCmd = ENABLE; // Enable interrupt
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; // Interrupt mode
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising; // Triggers on rising
- EXTI_Init(&EXTI_InitStruct); // Add to EXTI
- /* Add IRQ vector to NVIC */
- NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn; // PF0 is connected to EXTI_Line0, which has EXTI0_IRQn vector
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00; // Set priority
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00; // Set sub priority
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; // Enable interrupt
- NVIC_Init(&NVIC_InitStruct); // Add to NVIC
- }
- void EXTI0_IRQHandler(void){
- if (EXTI_GetITStatus(EXTI_Line0) != RESET) // Make sure that interrupt flag is set
- {
- uint8_t mainreg;
- mainreg = AS3911B_Read_Register(AS3911B_MAIN_IT); // Looking for IT Source, we have to read the 3 IT registers in 1 attempt
- if((mainreg & 0x01) == 0x01) // IRQ due to error and wake-up timer
- {
- uint8_t auxreg1 = AS3911B_Read_Register(AS3911B_ERROR_WAKEUP_IT); // Reading Auxiliary IT Register 2
- if (auxreg1 & 0x80) {} // CRC Error
- else if (auxreg1 & 0x40) {}// Parity error
- else if (auxreg1 & 0x20) {}// Soft framing error
- else if (auxreg1 & 0x10) {}// Hard framing error
- else if (auxreg1 & 0x08) {}// Wake-up interrupt
- else if (auxreg1 & 0x04) {}// Wake-up interrupt due to Amplitude Measurement
- else if (auxreg1 & 0x02) {}// Wake-up interrupt due to Phase Measurement
- else if (auxreg1 & 0x01) // Wake-up interrupt due to Capacitance Measurement
- {
- //cardPresent=1
- AS3911B_Enter_Ready_Mode();
- }
- }
- else if((mainreg & 0x02) == 0x02) // IRQ due to timer or NFC event
- {
- uint8_t auxreg2 = AS3911B_Read_Register(AS3911B_TIMER_NFC_IT);
- if (auxreg2 & 0x80) {TM_DISCO_LedOn(LED_GREEN);} // Termination of Direct Command
- else if (auxreg2 & 0x40) {}// No-response Timer expire
- else if (auxreg2 & 0x20) {}// GP Timer expire
- else if (auxreg2 & 0x10) {}// External field greater than target activation level
- else if (auxreg2 & 0x08) {}// External field less than target activation level
- else if (auxreg2 & 0x04) {}// Collision detected during RF Collision avoidance
- else if (auxreg2 & 0x02) {}// Minimum guard time expire
- else if (auxreg2 & 0x01) {}// Initiator bitrate recognized
- }
- else if((mainreg & 0x04) == 0x04) // IRQ due to bit collision
- {
- }
- else if((mainreg & 0x08) == 0x08) // IRQ due to end of transmission
- {
- }
- else if((mainreg & 0x10) == 0x10) // IRQ due to end of receive
- {
- }
- else if((mainreg & 0x20) == 0x20) // IRQ due to start of receive
- {
- }
- else if((mainreg & 0x40) == 0x40) // IRQ due to FIFO water level
- {
- }
- else if((mainreg & 0x80) == 0x80) // IRQ when oscillator frequency is stable
- {
- }
- EXTI_ClearITPendingBit(EXTI_Line0); // Clear interrupt flag
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement