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

BLE + ADC + optimisation level

Hello to everyone! Please, tell me, why ADC may can't be rightly initialised after BLE stack init? It's happen only when I use Optimisation level 0 instead 3. Thank you so much!

Parents
  • This is an initialisation of ADC:

        nrf_gpio_cfg_output(PIN_BATTERY_CHARGE_ON);
    nrf_gpio_pin_set(PIN_BATTERY_CHARGE_ON);
    
    /* Enable interrupt on ADC sample ready event*/		
    NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
    sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
    sd_nvic_EnableIRQ(ADC_IRQn);
    
    NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) | (ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos)	| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)		| (ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling << ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos);			
    
    /* Enable ADC*/
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    

    and this is a place when I'm try to get a data from ADC

    uint32_t p_is_running = 0;
    
    sd_clock_hfclk_request();
    while(! p_is_running) {  							//wait for the hfclk to be available
    	sd_clock_hfclk_is_running((&p_is_running));
    }               
    
    nrf_gpio_cfg_output(PIN_BATTERY_CHARGE_ON);
    nrf_gpio_pin_set(PIN_BATTERY_CHARGE_ON);
    
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    NRF_ADC->TASKS_START = 1;							//Start ADC sampling
    
    
    
    while (NRF_ADC->EVENTS_END == 0);
    

    }

    It's run on while (NRF_ADC->EVENTS_END == 0); again and again and in some runs go to HardFaultHandler

Reply
  • This is an initialisation of ADC:

        nrf_gpio_cfg_output(PIN_BATTERY_CHARGE_ON);
    nrf_gpio_pin_set(PIN_BATTERY_CHARGE_ON);
    
    /* Enable interrupt on ADC sample ready event*/		
    NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
    sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
    sd_nvic_EnableIRQ(ADC_IRQn);
    
    NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) | (ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos)	| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)		| (ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling << ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos);			
    
    /* Enable ADC*/
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    

    and this is a place when I'm try to get a data from ADC

    uint32_t p_is_running = 0;
    
    sd_clock_hfclk_request();
    while(! p_is_running) {  							//wait for the hfclk to be available
    	sd_clock_hfclk_is_running((&p_is_running));
    }               
    
    nrf_gpio_cfg_output(PIN_BATTERY_CHARGE_ON);
    nrf_gpio_pin_set(PIN_BATTERY_CHARGE_ON);
    
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    NRF_ADC->TASKS_START = 1;							//Start ADC sampling
    
    
    
    while (NRF_ADC->EVENTS_END == 0);
    

    }

    It's run on while (NRF_ADC->EVENTS_END == 0); again and again and in some runs go to HardFaultHandler

Children
Related