Tool/software:
How to configure GPIO interrupt for both rising and falling edge?
How to identify which edge (i.e. rising or falling) generates interrupt?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
How to configure GPIO interrupt for both rising and falling edge?
How to identify which edge (i.e. rising or falling) generates interrupt?
How to configure GPIO interrupt for both rising and falling edge?
To configure the GPIO pins to generate interrupt on both rising and falling edge, we need to set the GPIO trigger type to both rising and falling.
There are two registers (i.e. RIS_TRIG & FAL_TRIG) which specifies which edge (i.e. rising or falling) of GPIO signal generates an interrupt.
The RIS_TRIG and FAL_TRIG registers are not directly accessible or visible to the host CPU. These registers are accessed indirectly through four registers: SET_RIS_TRIG, CLR_RIS_TRIG, SET_FAL_TRIG, and CLR_FAL_TRIG.
Writing 1 to a bit on the SET_RIS_TRIG register sets the corresponding bit on the RIS_TRIG register. Writing 1 to a bit of the CLR_RIS_TRIG register clears the corresponding bit on the RIS_TRIG register.
Writing to the SET_FAL_TRIG and CLR_FAL_TRIG registers works the same way on the FAL_TRIG register.
You can configure the GPIO trigger type by modifying the example.syscfg file as shown below.
Please refer below image.
Also enable the interrupt configuration for GPIO to generate interrupts.
After configuring the trigger type & enabling interrupts, please register the GPIO interrupt in the application code using HwiP APIs with an appropriate callback function.
Please refer below code to register an interrupt.
/* Register gpio interrupt */
HwiP_Params_init(&hwiPrms);
hwiPrms.intNum = gGpioBankIntrNum;
hwiPrms.callback = &GPIO_bankIsrFxn;
hwiPrms.args = (void *) pinNum;
retVal = HwiP_construct(&gGpioHwiObject, &hwiPrms);
if(SystemP_SUCCESS != retVal)
{
DebugP_assert(FALSE);
}
How to identify which edge (i.e. rising or falling) generates interrupt?
Read the GPIO_IN_DATA register at the beginning of the ISR. Please check for the GPIO_n bit whether it is high or low.
If the GPIO_IN_DATA register's GPIO_n bit is high the interrupt is caused by Rising edge and if it is low then interrupt is caused by Falling edge.
Use the below API to read the GPIO pins value.
GPIO_pinRead(gGpioBaseAddr, pinNum);
In the ISR you can check which edge is generating interrupt by reading the pin value.
Please refer below code.
static void GPIO_bankIsrFxn(void *args) { uint32_t pinNum = (uint32_t) args, bankNum; uint32_t intrStatus, pinMask = GPIO_GET_BANK_BIT_MASK(pinNum); bankNum = GPIO_GET_BANK_INDEX(pinNum); uint32_t status = GPIO_readPin(gGpioBaseAddr, pinNum); if(status == 1){/* Interrupt generated by Rising edge */} else {/* Interrupt generated by Falling edge */} intrStatus = GPIO_getBankIntrStatus(gGpioBaseAddr, bankNum); GPIO_clearBankIntrStatus(gGpioBaseAddr, bankNum, intrStatus); }