中级会员
- 积分
- 208
- 金钱
- 208
- 注册时间
- 2013-9-23
- 在线时间
- 24 小时
|
30金钱
hi,代码如下,STM32F030多路ADC采集,当某一路的电压示数跳变了,会导致另外一个引脚的电压改变,是哪里设置的有问题么?
[mw_shl_code=c,true]void ADC1_DMA_Init1(void)
{
ADC_InitTypeDef ADC_InitStruct;
DMA_InitTypeDef DMA_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
/* ADC1 DeInit */
ADC_DeInit(ADC1);
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* DMA1 clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div4);
/* Configure PA.1 as analog input */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStruct);
/* DMA1 Channel1 Config */
DMA_DeInit(DMA1_Channel1);
DMA_InitStruct.DMA_PeripheralBaseAddr = (u32)&(ADC1->DR);
DMA_InitStruct.DMA_MemoryBaseAddr = (u32)RegularConvData_Tab1;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStruct.DMA_BufferSize = 4;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_High;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStruct);
/* DMA1 Channel1 enable */
DMA_Cmd(DMA1_Channel1, ENABLE);
/*Enables the specified DMAy Channelx interrupts */
// DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE);
/* ADC DMA request in circular mode */
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
/* Enable ADC_DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStruct);
/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits */
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Backward;
ADC_Init(ADC1, &ADC_InitStruct);
ADC_ChannelConfig(ADC1, ADC_Channel_4, ADC_SampleTime_55_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_5, ADC_SampleTime_55_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_6, ADC_SampleTime_55_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_7, ADC_SampleTime_55_5Cycles);
/* ADCD£×? */
ADC_GetCalibrationFactor(ADC1);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
*/
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
}
采集:
if(DMA_GetFlagStatus(DMA1_FLAG_TC1) != RESET)
{
adc_data1[adc_count]=RegularConvData_Tab1[0];
adc_data2[adc_count]=RegularConvData_Tab1[1];
adc_data3[adc_count]=RegularConvData_Tab1[2];
adc_data4[adc_count]=RegularConvData_Tab1[3];
DMA_ClearFlag(DMA1_FLAG_TC1);
}[/mw_shl_code]
|
最佳答案
查看完整内容[请看2#楼]
这个是解决的了。忙着搞毕设没时间,现在补贴上 。。
读RegularConvData_Tab数组就行了,添加通道注意要配置数组与DMA的缓存大小。
[mw_shl_code=c,true]#include "adc.h"
#define ADC1_DR_Address 0x40012440
__IO uint16_t RegularConvData_Tab[2];
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------- ...
|