#define ADC1_DR_ADDRESS ((uint16_t)0x5344)
#define BUFFER_SIZE ((uint8_t) 0x08)
#define BUFFER_ADDRESS ((uint16_t)(&Buffer))
signed int Buffer[BUFFER_SIZE] = {0,0,0,0,0,0,0,0};
void ADC_DMAInit(void)
{
ADC_DeInit(ADC1);
DMA_GlobalDeInit();
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1,ENABLE);
CLK_PeripheralClockConfig(CLK_Peripheral_DMA1,ENABLE);
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);
ADC_Cmd(ADC1, ENABLE);
ADC_ChannelCmd(ADC1,ADC_Channel_2,ENABLE);//电位器4
ADC_ChannelCmd(ADC1,ADC_Channel_8,ENABLE);//电位器3
ADC_ChannelCmd(ADC1,ADC_Channel_9,ENABLE);//电位器2
ADC_ChannelCmd(ADC1,ADC_Channel_10,ENABLE);//电位器1
ADC_ChannelCmd(ADC1,ADC_Channel_18,ENABLE);
ADC_ChannelCmd(ADC1,ADC_Channel_19,ENABLE);
ADC_ChannelCmd(ADC1,ADC_Channel_20,ENABLE);
ADC_ChannelCmd(ADC1,ADC_Channel_21,ENABLE);
SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
DMA_Init(
DMA1_Channel0,
BUFFER_ADDRESS,
ADC1_DR_ADDRESS,
BUFFER_SIZE,
DMA_DIR_PeripheralToMemory,
DMA_Mode_Circular,
DMA_MemoryIncMode_Inc,
DMA_Priority_High,
DMA_MemoryDataSize_HalfWord);
DMA_Cmd(DMA1_Channel0, ENABLE);
DMA_ITConfig(DMA1_Channel0,DMA_ITx_TC,ENABLE);
DMA_GlobalCmd(ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_SoftwareStartConv(ADC1);
ADC_ExternalTrigConfig(ADC1, ADC_ExtEventSelection_Trigger2,
ADC_ExtTRGSensitivity_Falling);
}
程序是参照官方例程写的,中断里没有进行操作,只是程序里对读数Buffer数组里的数进行操作,上电运行刚开始正常,但过一些时间后出现读出来的Buffer[]与设置好的AD口不对应,如Buffer[0]可能是电位器2的读数,也可能电位器3等其他读数,请大神帮忙解决下
|
|