AnsweredAssumed Answered

STM32 ADC (internal temperature sensor) interrupt problem

Question asked by gt on Jul 30, 2013
Hi,
I am working on a project and I need to use internal temperature sensor on STM32VLDISCOVERY board. I want to use ADC in single channel single mode and I made ADC configurations according to that as you can see from the code below. I want it to make one single conversion and after that, enter ISR, get data from ADC data register and start conversion again by software.

When I check the code in debug mode, I saw that it makes configurations, enables EOCIE, makes conversion and loads data to ADC data register and when conversion ends, EOC bit is enabled. However, after that, it does not go into ISR and I couldn't figure out why. I check the ISR name from the vector table and it is also correct. (By the way, I don't know if it is relevant or not but I have a 16 MHz crystal instead of standard 8 MHz on discovery board.)
Thanks in advance.
01.int main(void){
02.  
03.    ADC_InitTypeDef ADC_InitStructure;
04.    NVIC_InitTypeDef NVIC_InitStructure;
05.  
06.    ADC_DeInit(ADC1);
07.  
08.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOC, ENABLE);
09.    //PCLK2 = 24 MHz, 24/2 = 12 < 14
10.    RCC_ADCCLKConfig(RCC_PCLK2_Div2);
11.    NVIC_InitStructure.NVIC_IRQChannel = ENABLE;
12.    NVIC_InitStructure.NVIC_IRQChannelCmd = ADC1_IRQn;
13.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
14.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
15.    NVIC_Init(&NVIC_InitStructure);
16.    ADC_InitTypeDef ADC_InitStructure;
17.    ADC_DeInit(ADC1);
18.    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
19.    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
20.    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
21.    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
22.    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
23.    ADC_InitStructure.ADC_NbrOfChannel = 1;
24.    ADC_Init(ADC1, &ADC_InitStructure);
25.   
26.    ADC_TempSensorVrefintCmd(ENABLE);
27.    ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_239Cycles5);
28.    ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
29.    ADC_Cmd(ADC1, ENABLE);
30.    ADC_ResetCalibration(ADC1);
31.    while(ADC_GetResetCalibrationStatus(ADC1)){}
32.    ADC_StartCalibration(ADC1);
33.    while(ADC_GetCalibrationStatus(ADC1)){}
34.    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
35.    while(1)
36.    {
37.    }
38.}
01./*ISR*/
02.void ADC1_IRQHandler(void)
03.{
04.uint16_t adc_result, temp;
05.    if(ADC_GetITStatus(ADC1, ADC_IT_EOC)){
06.        if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9)){
07.            GPIO_WriteBit(GPIOC, GPIO_Pin_9, RESET);
08.        }else{
09.            GPIO_WriteBit(GPIOC, GPIO_Pin_9, SET);
10.        }
11.        adc_result = ADC_GetConversionValue(ADC1);
12.        temp = (uint16_t)((1750 - adc_result)/5+25);
13.        ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
14.        ADC_SoftwareStartConvCmd(ADC1, ENABLE);
15. 
16.  }
17.}

Outcomes