Question
Reading voltage -ADC
Posted on February 27, 2012 at 11:29
hi..
I'm using STM32 VL microcontroller.I need to read voltage continiously..so i'm using timer 2 in interupt mode to read ADC value.below is my code.. wheneven ADCread value function is colled from TIM2 interrupt, i goes to infine loop in while function.. Can any body tell me why its happening like that.or is that any alternate method to implement..?? int main() { NVIC_config(); // timer 2 interrupt Timer2_config(); ADC_config(); While(1) {} } int ADCReadValue() { ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_1Cycles5); ADC_SoftwareStartConvCmd(ADC1, ENABLE); // code hangs in this while loop while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); return ADC_GetConversionValue(ADC1); } void TIM2_IRQHandler() { if(TIM_GetITStatus(TIM@, TIM_IT_Update) != RESET) { readADCValue(); TIM_ClearITPendingBit(TIM2, TIM_IT_Update); } } #timer #adc #stm32 #adc-and-tim2-interrupt.