WICED Sense button interrupt not working

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

I've been trying to get the interrupt working for a button press using the WICED Sense tag board  and the SDK 2.2.0 however for some reason the interrupt only works when the lower button is pressed. The function handler is

// Three Interrupt inputs (Buttons) can be handled here.

// If the following value == 1, Button is pressed. Different than initial value.

// If the following value == 0, Button is depressed. Same as initial value.

// Button1 : value&0x01

// Button2 : (value&0x02)>>1

// Button3 : (value&0x04)>>2

void rtls_beacon_interrupt_handler(UINT8 value)

where value contains which button is pressed. If the lower button is pressed, value = 0b00000001. The problem is the top button does not trigger the interrupt at all.

0 Likes
1 Solution
Anonymous
Not applicable

OK I found the issue since only having one button functional didn't make any sense.


Any asterisks here such as " *_db.c " mean anything can be contained there since everyone's naming will be different.

Identifying the issue

When using the WICED Smart Designer tool to generate new code you select "button" to enable buttons in your project, however button interrupts are only enabled on the "bottom" button (Button1-SW4 in the scematic PDF or K1 in the Mentor Graphics layout). Originally this single button is enabled by setting the values in the GPIO config found in the generated *_db.c file:

// Following structure defines GPIO configuration used by the application

const BLE_PROFILE_GPIO_CFG test_gpio_cfg =

{

    {

        GPIO_PIN_WP,                               // This need to be used to enable/disable NVRAM write protect

        GPIO_PIN_BATTERY, GPIO_PIN_BUTTON, GPIO_PIN_LED, GPIO_PIN_BUZZER,

        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // Other GPIOs are not used

    },

    /*.gpio_flag =*/

    {

        GPIO_SETTINGS_WP,

        GPIO_SETTINGS_BATTERY, GPIO_SETTINGS_BUTTON, GPIO_SETTINGS_LED, GPIO_SETTINGS_BUZZER,

        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    }

};

Then the GPIO is initialized in the *_create() function:

bleprofile_GPIOInit(bleprofile_gpio_p_cfg);

Then the interrupt is registered, also in the *_create() function:

bleprofile_regIntCb((BLEPROFILE_SINGLE_PARAM_CB) rtls_beacon_interrupt_handler);

Fixing the issue

In order to fix the issue we need to define both buttons in the *_gpio_cfg struct. The define "GPIO_PIN_BUTTON" equates to 0 so I opted to use the gpio driver enums instead which equate GPIO_PIN_P0 to 0 and GPIO_PIN_P4 to 4 (gpiodriver.h is already included at the top of the file).

Order does not matter in the struct, simply match them in the same slots (ie. GPIO_PIN_P0 is at index 2, GPIO_SETTINGS_BUTTON is also at index 2 and so on).

// Following structure defines GPIO configuration used by the application

const BLE_PROFILE_GPIO_CFG test_gpio_cfg =

{

    {

        GPIO_PIN_WP,                               // This need to be used to enable/disable NVRAM write protect

        GPIO_PIN_BATTERY,

        GPIO_PIN_P0,

        GPIO_PIN_P4,

        GPIO_PIN_LED,

        GPIO_PIN_BUZZER,

        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1     // Other GPIOs are not used

    },

    /*.gpio_flag =*/

    {

        GPIO_SETTINGS_WP,

        GPIO_SETTINGS_BATTERY,

        GPIO_SETTINGS_BUTTON,

        GPIO_SETTINGS_BUTTON,

        GPIO_SETTINGS_LED,

        GPIO_SETTINGS_BUZZER,

        0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    }

};

Then comment out the function call "bleprofile_regIntCb()" in your *_create() function and add instead:

// Register for interrupts from GPIOs

UINT16 masks[3] = {(1 << 4) | (1 << 0), 0 , 0};

gpio_registerForInterrupt(masks, test_gpio_interrupt_handler, 0);

Make sure to include " *_gpio_interrupt_handler " as a new function to replace " *_interrupt_handler ":

/******************************************************

*               Function Prototypes

******************************************************/

static void test_gpio_interrupt_handler(void* unused, UINT8 gpio);

/******************************************************

*               Function Definitions

******************************************************/

// The GPIO interrupt handler.

void test_gpio_interrupt_handler(void* unused, UINT8 gpio)

{

    switch(gpio)

    {

    case GPIO_PIN_P4:

        // Do whatever when button is pressed.

        break;

    case GPIO_PIN_P0:

        // Do whatever when button is pressed.

        break;

    default:

        break;

    }

}

Alternatively

Remove any references to buttons in the gpio config struct and configure the pins separately after registering the gpio interrupt using:

gpio_configurePin(GPIO_PIN_P0 / 16, GPIO_PIN_P0 % 16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

gpio_configurePin(GPIO_PIN_P4 / 16, GPIO_PIN_P4 % 16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

If I goofed in the explanation, all of this is cobbled together from the WICED Sense demo app in the SDK.

View solution in original post

2 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

Only one of the two buttons on the WICED Sense device is functional.

0 Likes
Anonymous
Not applicable

OK I found the issue since only having one button functional didn't make any sense.


Any asterisks here such as " *_db.c " mean anything can be contained there since everyone's naming will be different.

Identifying the issue

When using the WICED Smart Designer tool to generate new code you select "button" to enable buttons in your project, however button interrupts are only enabled on the "bottom" button (Button1-SW4 in the scematic PDF or K1 in the Mentor Graphics layout). Originally this single button is enabled by setting the values in the GPIO config found in the generated *_db.c file:

// Following structure defines GPIO configuration used by the application

const BLE_PROFILE_GPIO_CFG test_gpio_cfg =

{

    {

        GPIO_PIN_WP,                               // This need to be used to enable/disable NVRAM write protect

        GPIO_PIN_BATTERY, GPIO_PIN_BUTTON, GPIO_PIN_LED, GPIO_PIN_BUZZER,

        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // Other GPIOs are not used

    },

    /*.gpio_flag =*/

    {

        GPIO_SETTINGS_WP,

        GPIO_SETTINGS_BATTERY, GPIO_SETTINGS_BUTTON, GPIO_SETTINGS_LED, GPIO_SETTINGS_BUZZER,

        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    }

};

Then the GPIO is initialized in the *_create() function:

bleprofile_GPIOInit(bleprofile_gpio_p_cfg);

Then the interrupt is registered, also in the *_create() function:

bleprofile_regIntCb((BLEPROFILE_SINGLE_PARAM_CB) rtls_beacon_interrupt_handler);

Fixing the issue

In order to fix the issue we need to define both buttons in the *_gpio_cfg struct. The define "GPIO_PIN_BUTTON" equates to 0 so I opted to use the gpio driver enums instead which equate GPIO_PIN_P0 to 0 and GPIO_PIN_P4 to 4 (gpiodriver.h is already included at the top of the file).

Order does not matter in the struct, simply match them in the same slots (ie. GPIO_PIN_P0 is at index 2, GPIO_SETTINGS_BUTTON is also at index 2 and so on).

// Following structure defines GPIO configuration used by the application

const BLE_PROFILE_GPIO_CFG test_gpio_cfg =

{

    {

        GPIO_PIN_WP,                               // This need to be used to enable/disable NVRAM write protect

        GPIO_PIN_BATTERY,

        GPIO_PIN_P0,

        GPIO_PIN_P4,

        GPIO_PIN_LED,

        GPIO_PIN_BUZZER,

        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1     // Other GPIOs are not used

    },

    /*.gpio_flag =*/

    {

        GPIO_SETTINGS_WP,

        GPIO_SETTINGS_BATTERY,

        GPIO_SETTINGS_BUTTON,

        GPIO_SETTINGS_BUTTON,

        GPIO_SETTINGS_LED,

        GPIO_SETTINGS_BUZZER,

        0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    }

};

Then comment out the function call "bleprofile_regIntCb()" in your *_create() function and add instead:

// Register for interrupts from GPIOs

UINT16 masks[3] = {(1 << 4) | (1 << 0), 0 , 0};

gpio_registerForInterrupt(masks, test_gpio_interrupt_handler, 0);

Make sure to include " *_gpio_interrupt_handler " as a new function to replace " *_interrupt_handler ":

/******************************************************

*               Function Prototypes

******************************************************/

static void test_gpio_interrupt_handler(void* unused, UINT8 gpio);

/******************************************************

*               Function Definitions

******************************************************/

// The GPIO interrupt handler.

void test_gpio_interrupt_handler(void* unused, UINT8 gpio)

{

    switch(gpio)

    {

    case GPIO_PIN_P4:

        // Do whatever when button is pressed.

        break;

    case GPIO_PIN_P0:

        // Do whatever when button is pressed.

        break;

    default:

        break;

    }

}

Alternatively

Remove any references to buttons in the gpio config struct and configure the pins separately after registering the gpio interrupt using:

gpio_configurePin(GPIO_PIN_P0 / 16, GPIO_PIN_P0 % 16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

gpio_configurePin(GPIO_PIN_P4 / 16, GPIO_PIN_P4 % 16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

If I goofed in the explanation, all of this is cobbled together from the WICED Sense demo app in the SDK.