This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC Clear PPI After Compare

I Cant clear the RTC2 after a Compare Match. First Compare is Triggered. After that no more Interrupt is generated. Code:

static const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2);

static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        //nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
    	NRF_LOG_INFO("Compare\r\n");
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)
    {
        //nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
    	//NRF_LOG_INFO("Tick\r\n");
    }
}

ret_code_t err_code;
	

nrf_drv_rtc_config_t rtc_config = NRF_DRV_RTC_DEFAULT_CONFIG;	

// PPI Initialisieren:
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);

// Clock für RTC an:
err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);

nrf_drv_clock_lfclk_request(NULL);

// RTC für Zeitgeber. RTC1 hier verwendet. Clock: 10000Hz. 10: 1000 Ticks pro Sekunde:
rtc_config.prescaler = (uint16_t)4095;

err_code = nrf_drv_rtc_init(&rtc, &rtc_config, rtc_handler);
APP_ERROR_CHECK(err_code);

// Tick Event anschalten:
nrf_drv_rtc_tick_enable(&rtc, false);

// Kein Interrupt
err_code = nrf_drv_rtc_cc_set(&rtc, 0, (uint32_t)TLC_SPIPufferOutMS, true);
APP_ERROR_CHECK(err_code);

// PPI Clear bei Compare:
err_code = nrf_drv_ppi_channel_alloc(&ppi_rtc_comp_clear);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_ppi_channel_assign(ppi_rtc_comp_clear,
                                      nrf_rtc_event_address_get(NRF_RTC2, NRF_RTC_EVENT_COMPARE_0),
                                      nrf_rtc_task_address_get(NRF_RTC2, NRF_RTC_TASK_CLEAR));
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_ppi_channel_enable(ppi_rtc_comp_clear);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_spi_xfer(&tlc_spi, &xfer, flags);
APP_ERROR_CHECK(err_code);
if(err_code == NRF_SUCCESS)
{
	NRF_LOG_INFO("SPI Senden okay\r\n");

	// Verbinde Latch-Pin mit PPI:


// Starte den Timer und die Übertragung:
nrf_drv_rtc_enable(&rtc);

//==========================================================
#ifndef RTC_ENABLED
#define RTC_ENABLED 1
#endif
#if  RTC_ENABLED
// <o> RTC_DEFAULT_CONFIG_FREQUENCY - Frequency  <16-32768>


#ifndef RTC_DEFAULT_CONFIG_FREQUENCY
#define RTC_DEFAULT_CONFIG_FREQUENCY 32768
#endif

// <q> RTC_DEFAULT_CONFIG_RELIABLE  - Ensures safe compare event triggering


#ifndef RTC_DEFAULT_CONFIG_RELIABLE
#define RTC_DEFAULT_CONFIG_RELIABLE 0
#endif

// <o> RTC_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority


// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7

#ifndef RTC_DEFAULT_CONFIG_IRQ_PRIORITY
#define RTC_DEFAULT_CONFIG_IRQ_PRIORITY 7
#endif

// <q> RTC0_ENABLED  - Enable RTC0 instance


#ifndef RTC0_ENABLED
#define RTC0_ENABLED 0
#endif

// <q> RTC1_ENABLED  - Enable RTC1 instance


#ifndef RTC1_ENABLED
#define RTC1_ENABLED 0
#endif

// <q> RTC2_ENABLED  - Enable RTC2 instance


#ifndef RTC2_ENABLED
#define RTC2_ENABLED 1
#endif

// <o> NRF_MAXIMUM_LATENCY_US - Maximum possible time[us] in highest priority interrupt
#ifndef NRF_MAXIMUM_LATENCY_US
#define NRF_MAXIMUM_LATENCY_US 2000
#endif
Parents Reply Children
No Data
Related