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

How to block the code while interrupts are executing?

Hello,

I am working with S110 stack and the custom application. I wanted to use the ADC driver with blocking and interrupts enabled. But the application is blocking and it blocked the ISR thereby I am not getting ADC interrupt too. This is the configuration snippet:

void adc_init(void)
{

NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) | 
                  (ADC_CONFIG_PSEL_AnalogInput3 << ADC_CONFIG_PSEL_Pos) | 
                  (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) | 
                  (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) | 
                  (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);

NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;
NVIC_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);
NVIC_EnableIRQ(ADC_IRQn);
}

Blocking function is:

Conv_Completed = false;
NRF_ADC->TASKS_START = 1;
while(Conv_Completed == false);

ADC ISR is:

void ADC_IRQHandler(void)
{
uint32_t ADC_result;
NRF_ADC->EVENTS_END 	= 0;
NRF_ADC->TASKS_STOP 	= 1;

ADC_result				= NRF_ADC->RESULT;
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled;
Conv_Completed = true;
}

Can any one tell hoe to use blocking code ? I am not interested in using Scheduler since it will block the application events until the scheduler tasks are complete.

Regards,
Sowmya

Parents
  • In your case, you must make sure that the priority of ADC_IRQHandler() is higher than the priority where you wait for the Conv_Completed flag. How do you call that piece of code? As you have this problem, it seems it's called from a interrupt context. Either you should try to call it from the main context (effectively lowering its priority), or you need to increase the priority of ADC_IRQHandler().

Reply
  • In your case, you must make sure that the priority of ADC_IRQHandler() is higher than the priority where you wait for the Conv_Completed flag. How do you call that piece of code? As you have this problem, it seems it's called from a interrupt context. Either you should try to call it from the main context (effectively lowering its priority), or you need to increase the priority of ADC_IRQHandler().

Children
Related