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.

[CC2650/40]: Counting Interrupts at GPIO

Other Parts Discussed in Thread: CC2650

Hello TI,

I am new to CC2650+RTOS. I just need to understand How can I measure the number of Interrupts occurred at a GPIO pin. If there is any example program for this, please share. I need to count the number of Interrupts occurred at a pin and the pin signal drive the motor until the number of Interrupts reached to a certain value. Sorry for asking a basic question. Just asking while considering the CC-RTOS.

Please suggest~

Thanks n Regards


  • You can just add a counter into your callback function, once the counter is larger than certain number, then you can clear the interrupt. I just copied RTOS example and stripped it down to easier version

    /* * ======== buttonCallbackFxn ======== * Pin interrupt Callback function board buttons configured in the pinTable. * If Board_LED3 and Board_LED4 are defined, then we'll add them to the PIN * callback function. */ static uint8_t counter = 0; void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) { uint32_t currVal = 0; counter ++; if (counter > 10) { //clear interrupt PINCC26XX_clrPendInterrupt(Board_KEY_LEFT); PINCC26XX_clrPendInterrupt(Board_KEY_RIGHT); } else { /* Debounce logic, only toggle if the button is still pushed (low) */ CPUdelay(8000*50); if (!PIN_getInputValue(pinId)) { /* Toggle LED based on the button pressed */ switch (pinId) { case Board_KEY_LEFT: PIN_setOutputValue(buttonPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1)); break; case Board_KEY_RIGHT: PIN_setOutputValue(buttonPinHandle, Board_LED2, !PIN_getOutputValue(Board_LED2)); break; default: /* Do nothing */ break; } } } } /* * ======== main ======== */ int main() { PIN_init(BoardGpioInitTable); buttonPinHandle = PIN_open(&buttonPinState, BoardGpioInitTable); if(!buttonPinHandle) { while(1); } // trigger interrupt when you push board key left or board key right PIN_setInterrupt(buttonPinHandle, Board_KEY_LEFT|PIN_IRQ_NEGEDGE); PIN_setInterrupt(buttonPinHandle, Board_KEY_RIGHT|PIN_IRQ_NEGEDGE); // register call back function. PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn); /* enable interrupts and start SYS/BIOS */ BIOS_start(); return 0; }

  • Hello Christin,

    Thanks for your reply~
    I tried this but its not working properly. The button and LED is not responding correspondingly. As per the code, the Button press should work until counter reaches 10 but it stops before... Also what is the significance of using CPU delay here?
    Please suggest and correct~

    Thanks
  • I tested and it was working. what's your HW setup? how do you run your project?
  • i am using CCS and hardware is cc2650DK...
  • can you show me your project setup? do you have the jumpers in place? It does not make sense that such a simple program does not work for you. Were you able to go into the interrupt routine?

    Can you elaborate a bit more on how to test the code so that we don't spend too much time on writing back and forth to each other.
  • I changed here:
    PIN_setOutputValue(buttonPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1)); (no response)...............TO..........

    PIN_setOutputValue(ledPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1)); (responding)

    I said its working but after pressing 3-4 times, the LED is ON always, not responding further. So its responding only for few press (3-4).
  • You can't just change this to ledPinHandle. You need to see what pins are used it's in when the following function was called.
    buttonPinHandle = PIN_open(&buttonPinState, BoardGpioInitTable);

    Because I was lazy, so I have all my pins in the BoardGpioInitTable. Also in my program, I did not initialize any ledPinHandle unless you use default TI-RTOS file and do this
    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
    System_abort("Error initializing board LED pins\n");
    }
  • Hello Christin, I did the required changes but still the same situation; Please check.

    int main()
    {
    Task_Params taskParams;
    Board_initGeneral();

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
    System_abort("Error initializing board LED pins\n");
    }

    buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
    if(!buttonPinHandle) {
    while(1);
    }

    // trigger interrupt when you push board key left or board key right
    PIN_setInterrupt(buttonPinHandle, Board_KEY_LEFT|PIN_IRQ_NEGEDGE);
    PIN_setInterrupt(buttonPinHandle, Board_KEY_RIGHT|PIN_IRQ_NEGEDGE);

    /* Setup callback for button pins */
    if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
    System_abort("Error registering button callback function");
    }
  • are you able to enter the callback function? Are you running the default RTOS program now? It looks to me you just revert back to RTOS pin interrupt example, which should work out of box too