在线时间0 小时
UID305713
ST金币0
蝴蝶豆0
注册时间2011-7-14
新手上路
- 最后登录
- 2019-3-24
|
a0a.1 0b0c
问题点:单次扫描转换,转换不成功。
现象:小弟设置ADC1为单次扫描转换,BUFFER使能,使能EOC中断,实际外接通道为AIN0和AIN1(均为DC 5v),结果发现进入EOC中断后数据缓冲寄存器ADC_DBxR 中只有CHANNEL0的BUFFER中有转换的数据,CHANNEL0的BUFFER数据一直为0.
源代码:
/* Configure PB0,PB1 for ADC1 */
GPIO_Init(GPIOB, GPIO_PIN_0, GPIO_MODE_IN_FL_NO_IT); // Ain0
GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_FL_NO_IT); // Ain1
void Init_ADC1(void)
{
/* Initialize ADC1 in RESET value */
ADC1_DeInit();
/* Debug ADC1 scan mode */
ADC1_ConversionConfig(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_0, ADC1_ALIGN_RIGHT);
//Configure the single conversion mode and the channel 0 to convert
//Configure ADC1 conversion value right align
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL0, DISABLE);
//Disable the schmitt trigger channel0
ADC1_ConversionConfig(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_1, ADC1_ALIGN_RIGHT);
//Configure the single conversion mode and the channel 1 to convert
//Configure ADC1 conversion value right align
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL1, DISABLE);
//Disable the schmitt trigger channel1
ADC1_ScanModeCmd(ENABLE); //Enable scan mode
ADC1_DataBufferCmd(ENABLE); //Enable the ADC1 data store into the Data Buffer registers
ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE); //Enable EOC interrupt
}
/* start up converting every 500ms */
ADC1_Cmd(ENABLE); //Wake up ADC1
Delay(2);
ADC1_Cmd(ENABLE); //Start up conversion
INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
/* Debug code */
if(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == 0x80)
{
ADC1_AIN0_Value = ADC1_GetBufferValue(0);
ADC1_AIN1_Value = ADC1_GetBufferValue(1);
ADC1_AIN2_Value = ADC1_GetBufferValue(2);
ADC1_AIN3_Value = ADC1_GetBufferValue(3);
ADC1_AIN4_Value = ADC1_GetBufferValue(4);
ADC1_AIN5_Value = ADC1_GetBufferValue(5);
ADC1_AIN6_Value = ADC1_GetBufferValue(6);
ADC1_AIN7_Value = ADC1_GetBufferValue(7);
ADC1_AIN8_Value = ADC1_GetBufferValue(8);
ADC1_AIN9_Value = ADC1_GetBufferValue(9);
ADC1_ClearITPendingBit(ADC1_IT_EOC);
ADC1_Cmd(DISABLE); //Close conversion
}
}
调试的结果:ADC1_AIN0_Value 读入值正确,ADC1_AIN1_Value 一直为0(实际应为非0).
注:本人通过单通道轮询转换的方式,转换可行。
由于小弟刚使用STM8,请各位大侠不吝赐教!! |
|