金牌会员
- 积分
- 2555
- 金钱
- 2555
- 注册时间
- 2017-12-16
- 在线时间
- 188 小时
|
50金钱
本帖最后由 sfd123 于 2023-11-10 08:31 编辑
adc配置如下:ADC_CHN_NUM = 2,ADC_DATA_NUM = 50
- void adc_init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- ADC_InitTypeDef ADC_InitStructure;
- ADC_CommonInitTypeDef ADC_CommonInitStructure;
- DMA_InitTypeDef DMA_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
- /*GPIO初始化*/
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
-
- //ADC3
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
- GPIO_Init(GPIOF, &GPIO_InitStructure);
- /*DMA初始化*/
- DMA_Cmd(DMA2_Stream0, DISABLE);
- DMA_DeInit(DMA2_Stream0);
- while(DMA_GetCmdStatus(DMA2_Stream0)!=DISABLE);
- DMA_InitStructure.DMA_Channel = DMA_Channel_2;
- DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&ADC3->DR);
- DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)g_adc_data;//g_adc_data[ADC_CHN_NUM*ADC_DATA_NUM]
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
- DMA_InitStructure.DMA_BufferSize = ADC_CHN_NUM*ADC_DATA_NUM;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_InitStructure.DMA_Mode = 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); //stream3 channel_1对应外设ADC2
- DMA_Cmd(DMA2_Stream0, ENABLE);
- ADC_DeInit();
- /*ADC初始化*/
- ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
- ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;
- ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
- ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;
- 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 = ADC_CHN_NUM;
- ADC_Init(ADC3, &ADC_InitStructure);
- //ADC_Cmd(ADC3, ENABLE);
- ADC_RegularChannelConfig(ADC3, ADC_Channel_14, 1, ADC_SampleTime_480Cycles);
- ADC_RegularChannelConfig(ADC3, ADC_Channel_15, 2, ADC_SampleTime_480Cycles);
- ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);
- ADC_DMACmd(ADC3, ENABLE);
- ADC_Cmd(ADC3, DISABLE);
- }
复制代码
启动ADC后,查看实时内存,发现只要不关闭ADC,[size=13.3333px]g_adc_data 数据一直在更新,并不是更新了2*50后 就停止了
[size=13.3333px]
[size=13.3333px]请帮忙看看配置哪里出的问题,多谢!
|
|