After writing that article for a few days, I thought it was too long to start writing it again.
Gpio is finished in the previous article. At this point, if you add a few buttons to capture, you can use the button to control the light. So what should I do if I want to use the interrupt?
Let's look at the example. I really don't know how to do it.
In the interrupt events chapter in the manual, we have mentioned the interrupt vector controller (ipvc) and the external interrupt/event controller (exit ). In the example, there are two functions used for interrupt:
void NVIC_Configuration(void); // void EXTI_Configuration(void);//Extern Interrput and Event controller configuration
Okay. Let's look at Objective C and the interrupt vector controller first.
/** * @brief NVIC Init Structure definition */typedef struct{ uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. This parameter can be a value of @ref IRQn_Type (For the complete STM32 Devices IRQ Channels list, please refer to stm32f10x.h file) */ uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel specified in NVIC_IRQChannel. This parameter can be a value between 0 and 15 as described in the table @ref NVIC_Priority_Table */ uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified in NVIC_IRQChannel. This parameter can be a value between 0 and 15 as described in the table @ref NVIC_Priority_Table */ FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel will be enabled or disabled. This parameter can be set either to ENABLE or DISABLE */ } NVIC_InitTypeDef;
/** @defgroup NVIC_Priority_Table * @{ *//**@code The table below gives the allowed values of the pre-emption priority and subpriority according to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function ============================================================================================================================ NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description ============================================================================================================================ NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority | | | 4 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority | | | 3 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority | | | 2 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority | | | 1 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority | | | 0 bits for subpriority ============================================================================================================================@endcode
It seems that this structure is relatively simple. There is an interrupt number, an interrupt priority, a subpriority, and a switch.
There seems to be nothing to say about this part. Let's look at the next one, the External Interrupt event controller.
**************************************** **************************************** ****************************************
The external interrupt/event controller consists of 19 edge detectors that generate event/interrupt requirements. The input type can be configured separately for each input line
(Pulse or suspension) and the corresponding trigger event (both the rising and bottom sides or the bilateral edges are triggered ). Each input line can be a stand-alone Screen
. The pending register maintains the interrupt requirements of the Status line.
To generate an interruption, you must first configure and enable disconnection. Set two trigger registers based on the required edge detection.
Write '1' to the corresponding bit of the disconnect mask register to allow the request to be interrupted. When the External Interrupt line has an expected edge,
When the request is interrupted, the corresponding pending bit is set to '1 '. Write '1' at the corresponding bit of the pending register to clear the interrupt request.
To generate an event, configure and enable the event line first. Set two trigger storages Based on the required edge detection.
And write '1' in the corresponding bit of the event shield register to allow Event requests. When the required edge occurs online
Generates an event request pulse, and the corresponding pending bit is not set to '1 '.
By writing '1' in the software interrupt/event register, you can also generate interrupt/Event requests through the software.
Exti register structure, exti_typedef, which is defined in the file "stm32f10x_map.h" as follows:
Typedef struct
{
Vu32 IMR;
Vu32 EMR;
Vu32 rtsr;
Vu32 ftsr;
Vu32 Swier;
Vu32 PR;
} Exti_typedef;
Register description
IMR interrupt shielding register
EMR event shielding register
Rtsr rising edge trigger Selection Register
Ftsr descent edge trigger Selection Register
Swir software interrupt event register
PR pending register
**************************************** **************************************** ****************************************
Void exti_configuration (void) {exti_inittypedef exti_initstruct; gpio_extilineconfig; // set the exti mode to interrupted. The other is an event. Exti_initstruct.exti_trigger = exti_trigger_falling; // falling down interruptexti_initstruct.exti_linecmd = Enable; exti_init (& exti_initstruct );}
/** * @brief EXTI Init Structure definition */typedef struct{ uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. This parameter can be any combination of @ref EXTI_Lines */ EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. This parameter can be a value of @ref EXTIMode_TypeDef */ EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. This parameter can be a value of @ref EXTIMode_TypeDef */ FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. This parameter can be set either to ENABLE or DISABLE */ }EXTI_InitTypeDef;
Why can't I see it all at once?