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.

CCS/CC2640R2F: Checking the status of a button (high or low)

Part Number: CC2640R2F

Tool/software: Code Composer Studio

Hello,

In my application I need to periodically check the status of a button. Ideally when the state changes, I'd like the state change to write to Characteristic4. Because one of the features of Characteristic4 is the ability to notify, my client application will receive a notification of the state change. I am using DIO13 as the button (just like the CC2640r2 LaunchPad). The button is configured as follows:

    Board_KEY1       | PIN_INPUT_EN  | PIN_PULLUP | PIN_HYSTERESIS | PIN_IRQ_NEGEDGE,           /* Button is active low          */

Schematically, this button is tied to GND in the closed state. So when the weight is on the button, DIO13 is at GND. This pin is also used to wakeup the device and initiate advertising. When the button is pushed a single time and immediately released (1-2 seconds), the device wakes up and begins advertising as expected. However when the button is held down by the weight for an extended period 10's of seconds, the device behaves strangely - the current draw increases by a factor of 10+, the device stops advertising sometimes, sometimes requires a power cycle to return to normal function.

For now, I'm updating the state change in the SimplePeripheral_performPeriodicTask(void) shown below.

static void SimplePeripheral_performPeriodicTask(void)
{

    AONBatMonEnable();
    int32_t temp = AONBatMonTemperatureGetDegC();
    uint32_t batVolt = AONBatMonBatteryVoltageGet();
    uint8_t buttonStatus = PIN_getInputValue(Board_PIN_BUTTON0);

    if(!AONBatMonNewTempMeasureReady())
        SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(int32_t), &temp);

    if(!AONBatMonNewBatteryMeasureReady())
        SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint32_t), &batVolt);

    //if(SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR4, &buttonStatus) == SUCCESS);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t), &buttonStatus);
}

Is my implementation incorrect for the application described?

Thanks,

Patrick

  • Hi. Please take a look at the project zero project which does exactly what you are requesting: it sends notifications when a button is pressed / released.
  • Hi Tim,

    Thanks for your suggestion, and yes you're right I probably should have started with projectZero. The full implementation of the function I'm looking for in projectZero is complicated. Unfortunately, I have a lot of time and effort invested in my variation of simplePeripheral. Based on the code snippet that I showed, can you see any reason why, with the button configured as it is and implemented in performPeriodicTask, it would not still work to initiate advertising and change CHAR4 with a state change? Do I need to do something else?

    Thanks,

    Patrick

  • I suggest you to set breakpoints to debug and trace your code.