Part Number: CC2640
Tool/software: TI-RTOS
Hello everyone,
I'm working on a custom board, where I have a button as following,
SW2 is normally open, so the signal PWR_DWN is pulled low by R1.
When SW2 is pushed (closed), the VCC_3V is tied directly to PWR_DWN and this pulls the PWR_DWN signal to a high.
I want to generate an interrupt to detect when the button is pressed. My code is ass follow,
static PIN_Handle buttonPinHandle;
static PIN_State buttonPinState;
PIN_Config buttonPinTable[] = {
IOID_19 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
PIN_TERMINATE
};
void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
System_printf("A button is pushed.\n"); System_flush();
/* Debounce logic, only toggle if the button is still pushed (low) */
//CPUdelay(8000*50);
if (PIN_getInputValue(pinId)) {
switch (pinId) {
case IOID_19:
System_printf("Button 1 is pushed.\n"); System_flush();
break;
default:
/* Do nothing */
break;
}
}
}
int main() {
// Call board init functions
Board_initGeneral();
I2C_init();
Board_initSPI();
Board_initUART();
// Board_initWatchdog();
PIN_setOutputValue(buttonPinHandle, IOID_19, 0);
buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
if(!buttonPinHandle) {
System_abort("Error initializing button pins\n");
}
/* Setup callback for button pins */
if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
System_abort("Error registering button callback function");
}
//PIN_setInterrupt(buttonPinHandle, IOID_19 | PIN_IRQ_NEGEDGE);
PIN_setConfig(buttonPinHandle, PIN_BM_IRQ, IOID_19 | PIN_IRQ_BOTHEDGES);
/* Start BIOS */
BIOS_start();
return 0;
}