Hi!
I'm trying to make a simple frequency meter with the nRF52-DK.
Actually, i'm trying to enable a simple timer, but my program freeze. I'm using mbed studio and I enable the nrfx_timer4 in the sdk_config.h
Here is my code:
#include "mbed.h"
#include "platform/mbed_thread.h"
#include "nrfx_timer.h"
// Blinking rate in milliseconds
#define BLINKING_RATE_MS 500
DigitalOut led2(LED2);
const nrfx_timer_t TIMER_LED = NRFX_TIMER_INSTANCE(4);
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
led2 = !led2;
break;
default:
//Do nothing.
break;
}
}
int main()
{
// Initialise the digital pin LED1 as an output
DigitalOut led(LED1);
uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
err_code = nrfx_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrfx_timer_ms_to_ticks(&TIMER_LED, time_ms);
nrfx_timer_extended_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL0,
time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
true);
nrfx_timer_enable(&TIMER_LED);
while (true) {
led = !led;
}
}
Thanks