I've been piecing examples together and I think I'm getting close. I'm using the NRF52 DK PCB.
I can get the RTC to trigger callbacks but it seems to be running way too fast. Prescaler is set to 32767 but I'm getting about 10 ticks per second.
I'm not able to get the PPI to trigger any activity on the ADC however. This is how I have the code setup:
void main(void) { rtc_init(); ppi_init(); adc_init(); while(1) ; } void rtc_init() { uint32_t err_code; // Initialize RTC instance nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG; config.prescaler = RTC_FREQ_TO_PRESCALER(1); printk("Prescaler = %d\n", config.prescaler); IRQ_CONNECT(DT_IRQN(DT_NODELABEL(rtc2)), DT_IRQ(DT_NODELABEL(rtc2), priority), nrfx_rtc_2_irq_handler, NULL, 0); err_code = nrfx_rtc_init(&rtc, &config, rtc_handler); ERR_CHECK(err_code, "rtc initialization error");; // Enable tick event & interrupt nrfx_rtc_tick_enable(&rtc, true); nrfx_rtc_enable(&rtc); } void ppi_init(void) { /**** RTC -> ADC *****/ // Trigger task sample from timer nrfx_err_t err_code = nrfx_ppi_channel_alloc(&m_timer_saadc_ppi_channel); ERR_CHECK(err_code, "PPI channel allocation error"); err_code = nrfx_ppi_channel_assign(m_timer_saadc_ppi_channel, nrfx_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK), nrf_saadc_task_address_get(DT_REG_ADDR(DT_NODELABEL(adc)), NRF_SAADC_TASK_SAMPLE)); ERR_CHECK(err_code, " PPI channel assignment error"); err_code = nrfx_ppi_channel_enable(m_timer_saadc_ppi_channel); ERR_CHECK(err_code, " PPI channel enable error"); } void adc_init(void) { nrfx_err_t err; nrfx_saadc_adv_config_t adc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG; err = nrfx_saadc_init(DT_IRQ(DT_NODELABEL(adc), priority)); ERR_CHECK(err, "nrfx_saadc init error"); err = nrfx_saadc_channels_config(adc_channels, NUM_ADC_CHANS); ERR_CHECK(err,"nrfx_saadc channel config error"); err = nrfx_saadc_advanced_mode_set(0b00000011, SAADC_RESOLUTION_VAL_14bit, &adc_adv_config, adc_handler); ERR_CHECK(err, "saadc setting advanced mode"); err = nrfx_saadc_buffer_set(&(adc_samples[CURRENT_BUFFER].samples[0]), NUM_ADC_CHANS); ERR_CHECK(err, "saadc buffer set"); }
My RTC tick handler is working (I have it print out a message on the UART) but the ADC handler doesn't seem to be called.
I'm not sure if I need to add an IRQ_CONNECT() for the adc. If I add
Existing handler 0x6389, new handler 0x4059
Has IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?
I have the following in my prj.conf: