My configuration:
- NRF51822 v2
- TWI
- GPIOTE
Issue:
The gpio interrupt does not get triggered. I know that my twi device is changing the state of the gpio3, because my logic analyzer captured such transition. But some how the adlx345_event_handler does not get executed. For testing purposes, I tried using the app_button and it works. Once the twi gets trigger it will stay high, so the gpiote has plenty of time to capture the event. I am not able to find any difference between the app_button gpiote configuration and my code. I used this code as a reference
Any hints are more than welcome :-)
#include <stdint.h>
#include <string.h>
#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "app_gpiote.h"
#include "app_error.h"
#define APP_GPIOTE_MAX_USERS 1
app_gpiote_user_id_t m_adxl345_irq_user_id;
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
NVIC_SystemReset();
}
static void adlx345_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
{
uint8_t data;
enum {FREE_FALL = 0x4, INACTIVITY = 0x8, ACTIVITY = 0x10, DTAP = 0x20, STAP = 0x40};
if (event_pins_low_to_high & 0x00000008)
{
}
if (event_pins_high_to_low & 0x00000008)
{
}
}
void configure_gpio_irq_ADXL345(void) {
uint32_t err_code;
uint32_t adxl345_irq_pin = 0xF;
nrf_gpio_cfg_input(adxl345_irq_pin, NRF_GPIO_PIN_PULLUP);
APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
err_code = app_gpiote_user_register(&m_adxl345_irq_user_id,
adxl345_irq_pin,
adxl345_irq_pin,
adlx345_event_handler);
if (err_code != NRF_SUCCESS)
{
APP_ERROR_CHECK(err_code);
}
err_code = app_gpiote_user_enable(m_adxl345_irq_user_id);
if (err_code != NRF_SUCCESS)
{
APP_ERROR_CHECK(err_code);
}
}
void ADLX345_setup(){
// Configure ADLX345
}
int main (void)
{
configure_gpio_irq_ADXL345();
init_i2c_master();
ADLX345_setup();
while(true);
}