学习GPIO中断要先知道跟GPIO中断设置的函数有哪些
第一步查看例程
- printf("P1.3/P4.5/P5.2/P6.1 are used to test interrupt ......\n");
- /* Configure P1.3 as Input mode and enable interrupt by rising edge trigger */
- GPIO_SetMode(P1, BIT3, GPIO_PMD_INPUT);
- GPIO_EnableInt(P1, 3, GPIO_INT_RISING);
- NVIC_EnableIRQ(GPIO_P0P1_IRQn);
- /* Configure P4.5 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
- GPIO_SetMode(P4, BIT5, GPIO_PMD_QUASI);
- GPIO_EnableInt(P4, 5, GPIO_INT_FALLING);
- NVIC_EnableIRQ(GPIO_P2P3P4_IRQn);
- /* Configure P5.2 as Input mode and enable interrupt by rising and falling edge trigger */
- GPIO_SetMode(P5, BIT2, GPIO_PMD_INPUT);
- GPIO_EnableInt(P5, 2, GPIO_INT_BOTH_EDGE);
- NVIC_EnableIRQ(GPIO_P5_IRQn);
- /* Configure P6.1 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
- GPIO_SetMode(P6, BIT1, GPIO_PMD_QUASI);
- GPIO_EnableInt(P6, 1, GPIO_INT_FALLING);
- NVIC_EnableIRQ(GPIO_P6P7_IRQn);
原来设置一个引脚为中断工作模式需要三步:
1、设置引脚的模式,模块有2种,准双向模式和输入模式
2、使能引脚的中断功能,设置边沿触发模式,有5种模式,一般都是用下降沿,上升沿,双边沿,另外2种不常用的是高电平,低电平
3、在嵌套中断向量控制器力使能对应的中断号入口
跟GPIO相关的一共4个参数。
然后就是讨论中断处理函数如何起作用了
先看示例
- void GPIOP0P1_IRQHandler(void)
- {
- /* To check if P1.3 interrupt occurred */
- if(GPIO_GET_INT_FLAG(P1, BIT3))
- {
- GPIO_CLR_INT_FLAG(P1, BIT3);
- printf("P1.3 INT occurred.\n");
- }
- else
- {
- /* Un-expected interrupt. Just clear all PORT0, PORT1 interrupts */
- P0->ISRC = P0->ISRC;
- P1->ISRC = P1->ISRC;
- printf("Un-expected interrupts.\n");
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Port2/Port3/Port4 IRQ
- *
- * @param None
- *
- * [url=home.php?mod=space&uid=266161]@return[/url] None
- *
- * [url=home.php?mod=space&uid=1543424]@Details[/url] The Port2/Port3/Port4 default IRQ, declared in startup_M058S.s.
- */
- void GPIOP2P3P4_IRQHandler(void)
- {
- /* To check if P4.5 interrupt occurred */
- if(GPIO_GET_INT_FLAG(P4, BIT5))
- {
- GPIO_CLR_INT_FLAG(P4, BIT5);
- printf("P4.5 INT occurred.\n");
- }
- else
- {
- /* Un-expected interrupt. Just clear all PORT2, PORT3 and PORT4 interrupts */
- P2->ISRC = P2->ISRC;
- P3->ISRC = P3->ISRC;
- P4->ISRC = P4->ISRC;
- printf("Un-expected interrupts.\n");
- }
- }
示例中直接定义了这几个函数就完成了中断的调用处理,那么这些函数名字是有什么讲究吗
原来在这个.s文件中定义了他们的函数名字,只需要按照这个列表中的名字定义函数,就可以在中断事件发生时候被调用了。
|