本帖最后由 sfd123-302670 于 2019-5-6 11:13 编辑 问题描述:有4个通道,使用两个ADC(ADC1和ADC2)同时采样,分别采样2路,采样10组数据,实际测试发现每启动一次采样,第一组数据的两个ADC1数据相同,确认是第二个ADC1的数据是错误的,接下来的9组数据都是正常的 请教:谁遇到过这样的问题?或者大侠指点一下应该怎么进一步调试确认?谢谢! ADC和DMA配置如下: void adc_init(void) { #define ADC_CDR_ADDRESS ((uint32_t)0x40012308) GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE); /*GPIO初始化*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_Init(GPIOA, &GPIO_InitStructure); /*DMA初始化*/ DMA_Cmd(DMA2_Stream0, DISABLE); DMA_DeInit(DMA2_Stream0); DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(ADC_CDR_ADDRESS); DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ADC_Convert_Value; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = (10 * 2); DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//DMA_Mode_Circular;//使用非循环模式就好了 DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); DMA_Cmd(DMA2_Stream0, ENABLE); DMA_Cmd(DMA2_Stream2, DISABLE); DMA_DeInit(DMA2_Stream2); DMA_InitStructure.DMA_Channel = DMA_Channel_1; DMA_Init(DMA2_Stream2, &DMA_InitStructure); DMA_Cmd(DMA2_Stream2, ENABLE); /*ADC初始化*/ ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 2; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_480Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_480Cycles); ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE); ADC_DMACmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); ADC_Init(ADC2, &ADC_InitStructure); ADC_RegularChannelConfig(ADC2, ADC_Channel_0, 1, ADC_SampleTime_480Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 2, ADC_SampleTime_480Cycles); ADC_DMACmd(ADC2, ENABLE); ADC_Cmd(ADC2, ENABLE); } |
STM32F207+LWIP的网络丢包问题! 【悬赏问答】
STM32F207+DP83848+RTL8019可不可以实现双网口设计
深圳市旺宝电子STM32F207开发板例程集
STM32F2 器件 -25° 上电正常 复位就挂了
STM32F229 TIMER CNT问题
哪位工程师有STM32F2xx的寄存器手册?
STM32F2xx RTC启动不了,求助!!!!
STM32F2外部按键触发中断问题
STM32F205 低功耗模式有BUG?
STM32F205 的HS USB 做device使用是否要接PHY?
评分
查看全部评分
你好,能再说的明白一点吗?我没理解,谢谢!
貌似ADC1-CHI和ADC2-CH1采集的是同一个通道,其实楼主采集4个通道,采用扫描方式使用ADC1就够了
我现在是验证ADC1+ADC2的方式,因为实际我需要10个通道同时采样,我是想每个ADC支持5个通道
昨天经过测试发现使用DMA_Mode_Normal模式数据就不乱了
谢谢你!
实际上ADC1或ADC2都可以采样16个通道,使用其中之一完全满足10通道ADC采样,无需使用2个ADC从而增加代码执行的复杂性。