请教版主,我用STM8L152做一个低功耗的东西。在外部中断到来时调用下面的函数,打开ADC采集电池电压,采集后关停ADC。
功能实现了,但发现调用退出后ADC没有关停。在线调试发现 ADC的寄存器 CR1 最低位(ADON)是1。本来应该是0的。不知道为什么。
麻烦版主指点。
unsigned char AdcGetData(void)
{
unsigned char tempdata;
CLK->PCKENR2 |= 0x01; // clock set on
ADC1->CR1 &= (uint8_t)~(ADC_CR1_CONT | ADC_CR1_RES); //clear CR1 register
ADC1->CR1 |= (uint8_t)((uint8_t)ADC_ConversionMode_Single | (uint8_t)ADC_Resolution_8Bit);
ADC1->CR2 &= (uint8_t)~(ADC_CR2_PRESC); //clear CR2 register
ADC1->CR2 |= (uint8_t) ADC_Prescaler_2;
ADC1->CR2 &= (uint8_t)~ADC_CR2_SMPT1;
ADC1->CR2 |= (uint8_t)ADC_SamplingTime_192Cycles;
ADC1->CR1 |= ADC_CR1_ADON; // ADC set on
Wait(31);
ADC1->SQR1 = 0x80; // no DMA
ADC1->SQR3 = 0x04; // use channnel 10
ADC1->TRIGR3 = 0x04;
Wait(37);
ADC1->CR1 |= ADC_CR1_START;
while( RESET == (ADC1->SR & ADC_FLAG_EOC) )
;
tempdata = (ADC1->DRL);
CLK->PCKENR2 &= ~0x01; // clock set off
ADC1->TRIGR3 = 0x04;
//ADC1->SQR[3] &= ~0x04;
ADC1->SR = 0x00;
ADC1->CR1 = 0x40; // ADC set off
Wait(41);
return tempdata;
} |