论坛里有没有人用过stm8l ADC DMA方式采集多路数据的,最近在使用的时候碰到一个问题,使用ADC1采样6个通道数据,采用DMA方式,采样结果通过串口显示出来,DAM通过定时器控制,每秒启动一次,一次采集8组DMA数据,多数时候六个通道数据采样都正确,发现偶尔会有一组数据出错,六个通道的采样数据均不对, 尝试了各种办法一直没解决,特向大家求助。 /* Enable ADC1 clock */ CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE); delay_10us(3); /* Enable DMA1 clock */ CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE); delay_10us(3); DMA_GlobalDeInit(); DMA_DeInit(DMA1_Channel0); ADC_DeInit(ADC1); /* Initialize and configure ADC1 */ ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2); ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles); ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_384Cycles); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 Channels 1 */ ADC_ChannelCmd(ADC1, ADC_Channel_1, ENABLE); /* connected to Potentiometer RV */ /* Enable ADC1 Channels 2 */ ADC_ChannelCmd(ADC1, ADC_Channel_2, ENABLE); /* connected to Potentiometer RV */ /* Enable ADC1 Channels 8 */ ADC_ChannelCmd(ADC1, ADC_Channel_8, ENABLE); /* connected to Potentiometer RV */ /* Enable ADC1 Channels 10 */ ADC_ChannelCmd(ADC1, ADC_Channel_10, ENABLE); /* connected to Potentiometer RV */ /* Enable ADC_Channel_TempSensor */ ADC_ChannelCmd(ADC1, ADC_Channel_TempSensor, ENABLE); /* connected to Potentiometer RV */ ADC_TempSensorCmd(ENABLE); ADC_SchmittTriggerConfig(ADC1, ADC_Channel_TempSensor, DISABLE); // Vref ADC_VrefintCmd(ENABLE); ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, ENABLE); ADC_SchmittTriggerConfig(ADC1, ADC_Channel_Vrefint, DISABLE); /* Connect ADC to DMA channel 0 */ SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0); DMA_Init(DMA1_Channel0, (uint32_t)(&AdcBuffer), ADC1_DR_ADDRESS, //(uint16_t)(sizeof(AdcBuffer) / 2), 6, DMA_DIR_PeripheralToMemory, DMA_Mode_Circular, DMA_MemoryIncMode_Inc, DMA_Priority_High, DMA_MemoryDataSize_HalfWord); /* DMA Channel0 enable */ DMA_Cmd(DMA1_Channel0, ENABLE); /* Enable DMA1 channel0 Transfer complete interrupt */ DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE); /* DMA enable */ DMA_GlobalCmd(ENABLE); /* Enable ADC1 DMA requests*/ ADC_DMACmd(ADC1, ENABLE); delay_ms(5); /* start ADC convertion by software */ ADC_SoftwareStartConv(ADC1); } |