Hi,
With the attached code, the timer0_event_handler() is only called once - is there something else I need to do in the ISR or at initialisation-time to ensure that it fires repeatedly?
#define NRFX_PPI_ENABLED 1
#include "sdk_config.h"
#include "nrf52.h"
#include "system_nrf52.h"
#define PIN_RED_LED 14
#define PIN_GREEN_LED 16
#define PIN_BLUE_LED 15
#include <stdint.h>
#include "app_error.h"
#include "nrfx_gpiote.h"
#include "nrfx_ppi.h"
#include "nrfx_clock.h"
#include "nrfx_rtc.h"
#include "nrfx_timer.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#define TIMER0_INTERVAL (1000) // Timer interval in milliseconds
#define TIMER1_INTERVAL (2000) // Timer interval in milliseconds
#define TIMER2_INTERVAL (2000) // Timer interval in milliseconds
static const nrfx_rtc_t m_rtc0 = NRFX_RTC_INSTANCE(0);
static const nrfx_timer_t m_timer0 = NRFX_TIMER_INSTANCE(0);
static const nrfx_timer_t m_timer1 = NRFX_TIMER_INSTANCE(1);
static const nrfx_timer_t m_timer2 = NRFX_TIMER_INSTANCE(2);
static nrf_ppi_channel_t m_ppi_channel1;
static nrf_ppi_channel_t m_ppi_channel2;
static volatile uint32_t m_counter;
static void timer0_event_handler(nrf_timer_event_t event_type, void * p_context)
{
static uint32_t state = 0;
nrfx_timer_clear(&m_timer0);
nrfx_timer_enable(&m_timer0);
...
}
...
/** @brief Function for Timer 0 initialization.
* @details It is configured to generate an interrupt every 1000ms.
*/
static void timer0_init(void)
{
// Check TIMER0 configuration for details.
nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
timer_cfg.frequency = NRF_TIMER_FREQ_4MHz;
ret_code_t err_code = nrfx_timer_init(&m_timer0, &timer_cfg, timer0_event_handler);
APP_ERROR_CHECK(err_code);
nrfx_timer_extended_compare(&m_timer0,
NRF_TIMER_CC_CHANNEL0,
nrfx_timer_ms_to_ticks(&m_timer0,
TIMER0_INTERVAL),
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
true);
}
...
int main(void)
{
SystemInit();
...
timer0_init();