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

nrf51822 tempeture based on interrupt

I can read temp value by pulling flag but I Want to do that by interrupt I added this code to my Keil but interrupt on temp didn't work. I use Adc interrupt like this definition.

static void temp_init(void){	

NRF_TEMP->INTENSET |= TEMP_INTENSET_DATARDY_Enabled;   
sd_nvic_SetPriority(TEMP_IRQn, NRF_APP_PRIORITY_LOW);  
sd_nvic_EnableIRQ(TEMP_IRQn);

NRF_TEMP->POWER = 1 ; 
}/* Interrupt handler for TEMP data ready event */
void TEMP_IRQHandler(void){
int32_t volatile temp;
    NRF_TEMP->EVENTS_DATARDY = 0;

    /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
    temp = (nrf_temp_read() / 4);

    /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
    NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */

    printf(" temperature: %d\n\r", (int)temp);
}
  • this my adc code: I copied. and start task in app timer and it works:

    //ADC initialization
    static void adc_init(void)
    {	
    /* 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) /* Bits 17..16 : ADC external reference pin selection. */
    								| (ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos)					/*!< Use analog input 2 as analog input. */
    								| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)							/*!< Use internal 1.2V bandgap voltage as reference for conversion. */
    									| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
    									| (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);									/*!< 8bit ADC resolution. */ 
    	
    	/* Enable ADC*/
    	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    }
    
    /* Interrupt handler for ADC data ready event */
    void ADC_IRQHandler(void)
    {
    	uint16_t adc_result;
    	
    	/* Clear dataready event */
      NRF_ADC->
    
    EVENTS_END = 0;	
    

    /* Write ADC result both to the UART and over BLE */ adc_result = NRF_ADC->RESULT; printf("ADC p01: %d / 1023\r\n",adc_result);

    //Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
      NRF_ADC->TASKS_STOP = 1;
    	
    	//Release the external crystal
    	//sd_clock_hfclk_release();
        }
    
Related