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.

LAUNCHXL-CC1310: cc1310_Button response

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Hi,

I am using cc1310 pin interrupt code. if i press button it is LED getting on , and if i press second time LED getting off. but, i want if i press button LED should glow, if i release button LED should off. Can you tell me the logic. I am not getting that. 

Actually my application is If i press switch1 from rf_packet board , It should show 1 in Tx_Packet, If if release the button it should show 0. This is my application.

Can anyone give me answer

  • Hi,

    please take the pinInterrupt example from the SDK and replace the pin configuration table and the pin callback function with the following code:

    PIN_Config ledPinTable[] = {
        Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES,
        Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW  | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    
    
    void onPinValueChanged(PIN_Handle handle, PIN_Id pinId)
    {
        // Delay for button debouncing
        CPUdelay(8000*10);
        // Only necessary when multiple buttons map to the same callback
    
        if (pinId == Board_PIN_BUTTON0)
        {
            // Read the current button status
            uint32_t value = PIN_getInputValue(Board_PIN_BUTTON0);
            // Write the inverted status to an output.
            PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, !value);
        }
    }

    In addition, please take the time and read the driver API documentation.

  • Hi,

    For blinking LED it is fine, I can able to get on whenever i pressed, but I want to print result in docklight either switch status 0 or 1, When we press switch it should print 1, after releasing switch it should print 0.

    for this i wrote condition like below, but I cannot able to get exactly, if one time press it shows 1, second time press means showing 0.

    void onPinValueChanged(PIN_Handle handle, PIN_Id pinId)
    {
    /* 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_PIN_BUTTON0:

    count1 = count1 + 1;

    if(((count1) % 2) == 0)
    {
    currVal1 = 0x01;
    }
    else
    {
    currVal1 = 0x00;
    }

    break;

    case Board_PIN_BUTTON1:

    count2 = count2 + 1;

    if(((count2) % 2) == 0)
    {
    currVal2 = 0x01;
    }
    else
    {
    currVal2 = 0x00;
    }

    break;

    default:
    /* Do nothing */
    break;
    }
    }
    }


    can you tell me any modifications for this . I want to print 1 whenever button pressed, if releases means it should show 0.

    Please guide me
  • The following line limits the following code to falling edges only:

    if (!PIN_getInputValue(pinId))

    Have you really understood the above example? Please also use the debugger to debug your program and see what is happening.

    You should also prepare for button bouncing. That is what the small delay at the top of your callback function is for that you have commented out. I suggest to use a logic analyzer to see how the button bounces.

  • Yeah, whatever code i forwarded it is getting struck and was opposite to my application, and can you tell me what logic to implement here for my application.

  • Sorry, I don't understand the question. What exactly is the problem? The code in my first reply showed how to get the current PIN status whenever an edge occurs. Then you have the information whether the button was pressed or released. In addition, you should add a short delay before reading the pin status. I will add the delay to my code example.