问题点:单次扫描转换,转换不成功。 现象:小弟设置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,请各位大侠不吝赐教!! |
从零开始操作STM8寄存器(风驰iCreate奉献)
【中文资料】初学STM8库函数的中文帮助软件
绝对经典的中文STM8学习手册,淘宝上学习板资料,友情大放送!
【原创教程】风驰iCreate独家开源STM8 27个例程和10多万字的pdf教程
STM8的LCD1602 4线驱动,为什么不工作
【精华资料】由零开始开发STM8
STM8S 的触摸库是如何在主程序中查询键的呢、
【精华资料】STM8的C语言编程1-14讲完整版
【精品教程】STM8系列单片机入门教程系列
STM8 第一次进中断不准【悬赏问答】
RE:关于STM8S ADC1单次扫描转换的问题
1、AD的时钟源没有开启。
2、 ADC1_GetBufferValue()代码获取AD值是否是对应AD的?
RE:关于STM8S ADC1单次扫描转换的问题
ADC1_PrescalerConfig(ADC1_PRESSEL_FCPU_D2);
//Prescaler selection fADC1 = fcpu/2
测试结果为:AIN0转换有效,AIN1一直无转换值(ADC1_AIN1_Value = 0,且ADC_DB1RH = 0和ADC_DB1RL = 0).
RE:关于STM8S ADC1单次扫描转换的问题
RE:关于STM8S ADC1单次扫描转换的问题
RE:关于STM8S ADC1单次扫描转换的问题
/**
* @brief Get one sample of measured signal.
* @param Buffer specifies the buffer to read.
* @retval BufferValue: value read from the given buffer.
* @par Required preconditions:
* ADC1 conversion finished.
*/
uint16_t ADC1_GetBufferValue(uint8_t Buffer)
{
uint16_t temph = 0;
uint8_t templ = 0;
/* Check the parameters */
assert_param(IS_ADC1_BUFFER_OK(Buffer));
if ((ADC1->CR2 & ADC1_CR2_ALIGN) != 0) /* Right alignment */
{
/* Read LSB first */
templ = *(uint8_t*)(uint16_t)((uint16_t)ADC1_BaseAddress + (uint8_t)(Buffer
RE:关于STM8S ADC1单次扫描转换的问题
所以,我怀疑单次扫描转换时,只转换了AIN0就产生中断,且AIN1一直未进行转换处理。原因为何不清楚?
RE:关于STM8S ADC1单次扫描转换的问题
RE:关于STM8S ADC1单次扫描转换的问题
RE:关于STM8S ADC1单次扫描转换的问题