cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 ADC (internal temperature sensor) interrupt problem

gizemtabak7
Associate II
Posted on July 30, 2013 at 09:15

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.

int

main(

void

){

ADC_InitTypeDef ADC_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

ADC_DeInit(ADC1);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOC, ENABLE);

//PCLK2 = 24 MHz, 24/2 = 12 < 14

RCC_ADCCLKConfig(RCC_PCLK2_Div2);

NVIC_InitStructure.NVIC_IRQChannel = ENABLE;

NVIC_InitStructure.NVIC_IRQChannelCmd = ADC1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_Init(&NVIC_InitStructure);

ADC_InitTypeDef ADC_InitStructure;

ADC_DeInit(ADC1);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

ADC_TempSensorVrefintCmd(ENABLE);

ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_239Cycles5);

ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

ADC_Cmd(ADC1, ENABLE);

ADC_ResetCalibration(ADC1);

while

(ADC_GetResetCalibrationStatus(ADC1)){}

ADC_StartCalibration(ADC1);

while

(ADC_GetCalibrationStatus(ADC1)){}

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

while

(1)

{

}

/*ISR*/

void

ADC1_IRQHandler(

void

)

{

uint16_t adc_result, temp;

if

(ADC_GetITStatus(ADC1, ADC_IT_EOC)){

if

(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9)){

GPIO_WriteBit(GPIOC, GPIO_Pin_9, RESET);

}

else

{

GPIO_WriteBit(GPIOC, GPIO_Pin_9, SET);

}

adc_result = ADC_GetConversionValue(ADC1);

temp = (uint16_t)((1750 - adc_result)/5+25);

ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

}

}

0 REPLIES 0