hello there i want to generate external interrupt from adxl345.can you help me? can we do same like we are using with button??
hello there i want to generate external interrupt from adxl345.can you help me? can we do same like we are using with button??
Hi rushin
Would this button press solution be useful to you, or do you want to use app_button directly?
By the way, what nRF51 SDK version are you using?
All that a button does is to change the voltage level on a GPIO pin to generate an interrupt. If an external circuit also changes the voltage level in the same way as a button does, you can use the same button code to detect an interrupt from an external circuit, as e.g. the adxl345.
Update 8.1.2016 To use app_button, you need to initialize app_timer and app_gpiote, because app_button uses those libraries internally. A good app_button code example is available on Github. The example is for nRF51 SDK 8.0.0 but it should also work for nRF51 SDK 10.0.0
Hi rushin
Would this button press solution be useful to you, or do you want to use app_button directly?
By the way, what nRF51 SDK version are you using?
All that a button does is to change the voltage level on a GPIO pin to generate an interrupt. If an external circuit also changes the voltage level in the same way as a button does, you can use the same button code to detect an interrupt from an external circuit, as e.g. the adxl345.
Update 8.1.2016 To use app_button, you need to initialize app_timer and app_gpiote, because app_button uses those libraries internally. A good app_button code example is available on Github. The example is for nRF51 SDK 8.0.0 but it should also work for nRF51 SDK 10.0.0
i am using nrf51 SDK10
ok i will try it
can i use above button event handler function i have written above??
this is not working
#include <stdbool.h> #include <string.h> #include "app_button.h" #include "boards.h" #include "app_gpiote.h" #include "app_timer.h"
#define APP_TIMER_PRESCALER 0 // Value of the RTC1 PRESCALER register.
#define APP_TIMER_MAX_TIMERS 1 // Maximum number of simultaneously created timers.
#define APP_TIMER_OP_QUEUE_SIZE 2 // Size of timer operation queues.
#define BUTTON_DEBOUNCE_DELAY 50 // Delay from a GPIOTE event until a button is reported as pushed.
#define APP_GPIOTE_MAX_USERS 1 // Maximum number of users of the GPIOTE handler.
/*
* Handler to be called when button is pushed.
* param[in] pin_no The pin number where the event is genereated
* param[in] button_action Is the button pushed or released
*/
static void button_handler(uint8_t pin_no, uint8_t button_action)
{
if(button_action == APP_BUTTON_PUSH)
{
switch(pin_no)
{
case BUTTON_1:
nrf_gpio_pin_toggle(LED_1);
break;
case BUTTON_2:
nrf_gpio_pin_toggle(LED_2);
break;
case BUTTON_3:
nrf_gpio_pin_toggle(LED_3);
break;
case BUTTON_4:
nrf_gpio_pin_toggle(LED_4);
break;
default:
break;
}
}
}
/**
* Initialize the clock.
*/
void init_clock()
{
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); // Wait for clock to start
}
/**
* Initialize all four LEDs on the nRF51 DK.
*/
void init_leds()
{
nrf_gpio_cfg_output(LED_1);
nrf_gpio_cfg_output(LED_2);
nrf_gpio_cfg_output(LED_3);
nrf_gpio_cfg_output(LED_4);
nrf_gpio_pin_set(LED_1);
nrf_gpio_pin_set(LED_2);
nrf_gpio_pin_set(LED_3);
nrf_gpio_pin_set(LED_4);
}
/**
* Function for application main entry.
*/
int main(void)
{
init_leds();
init_clock();
uint32_t err_code;
// Button configuration structure.
static app_button_cfg_t p_button[] = { {BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
{BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
{BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
{BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}};
// Macro for initializing the application timer module.
// It will handle dimensioning and allocation of the memory buffer required by the timer, making sure that the buffer is correctly aligned. It will also connect the timer module to the scheduler (if specified).
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
// Macro for initializing the GPIOTE module.
// It will handle dimensioning and allocation of the memory buffer required by the module, making sure that the buffer is correctly aligned.
APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
// Initializing the buttons.
err_code = app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), BUTTON_DEBOUNCE_DELAY);
APP_ERROR_CHECK(err_code);
// Enabling the buttons.
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
while(true)
{
// Do nothing.
}
}