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

NRF_ERROR_NO_MEM plus scheduler

I'm getting the NRF_ERROR_NO_MEM when I try to put my ADC interrupt routine into the scheduler. The code runs without error if I run from the ADC interrupt handler directly but hits the NVIC_system_reset if I try to put the code into the scheduler. I'm using the scheduler else where in my code without issue. This is with NRF51822 and SD 8. This works fine:


void ADC_IRQHandler(void){

nrf_adc_conversion_event_clean();
if (measure_bat == true)
{
	 batt_voltage = nrf_adc_result_get();
}
else if (measure_hwid == true)
{
	hwid = nrf_adc_result_get();
}

debug_uart_test();

measure_bat = false;
measure_hwid = false;

nrf_adc_input_select(NRF_ADC_CONFIG_INPUT_DISABLED);
NVIC_DisableIRQ(ADC_IRQn);

}


But if I try to do this, it resets with NRF_ERROR_NO_MEM


void ADC_IRQHandler(void) {

ret_code_t err_code; err_code = app_sched_event_put(NULL, 0, adc_scheduler_handler); APP_ERROR_CHECK(err_code);

}

void adc_scheduler_handler(void *data, uint16_t size) {

nrf_adc_conversion_event_clean();
if (measure_bat == true)
{
	batt_voltage = nrf_adc_result_get();
}
else if (measure_hwid == true)
{
	hwid = nrf_adc_result_get();
}

debug_uart_test();

measure_bat = false;
measure_hwid = false;

nrf_adc_input_select(NRF_ADC_CONFIG_INPUT_DISABLED);
NVIC_DisableIRQ(ADC_IRQn);

}


PS Any tips on how to format my code on this forum? The auto format doesn't seem to recognize chunks of my code...

  • I figured it out. I have to clear the ADC interrupt flag using nrf_adc_conversion_event_clean() in the ADC_IRQHandler(), I was putting that function in the scheduler handler. Since the scheduler handler is run in the main context it couldn't ever clear this flag. This caused the ADC interrupt to continuously be called.

    Now all I am doing in the ADC_IRQHandler() is nrf_adc_conversion_event_clean() and app_sched_event_put()

Related