dual adc input gpio is pc4(ADC1 input)、pc5(ADC2 input).
ADC1 gpio pc4 input sine wave,ADC2 gpio pc5 input is floating.
when dma mode use ADC_DMAAccessMode_2,ADC2 last sample data is also sine wave,why?
when change dma mode is ADC_DMAAccessMode_1,ADC2 result data is correct.
my code below,pls help with me,thanks.
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_TimeBaseInitStructure.TIM_Period = arr;
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
//TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
void dual_adc_gpio_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_GPIO_CLK1, ENABLE);
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_GPIO_CLK2, ENABLE);
GPIO_InitStructure.GPIO_Pin = RHEOSTAT_ADC_GPIO_PIN1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(RHEOSTAT_ADC_GPIO_PORT1, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = RHEOSTAT_ADC_GPIO_PIN2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(RHEOSTAT_ADC_GPIO_PORT2, &GPIO_InitStructure);
}
void dual_adc_init()
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_DMA_CLK, ENABLE);
RCC_APB2PeriphClockCmd(RHEOSTAT_ADC1_CLK , ENABLE);
RCC_APB2PeriphClockCmd(RHEOSTAT_ADC2_CLK , ENABLE);
#if 1
NVIC_SetPriorityGrouping(2);
//DMA_ITConfig( DMA2_Stream0 , DMA_IT_TC , ENABLE);
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannel=DMA2_Stream0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_InitStruct);
#endif
DMA_InitStructure.DMA_PeripheralBaseAddr = RHEOSTAT_ADC_CDR_ADDR;
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)g_adc_dma_buf1;
DMA_InitStructure.DMA_Memory1BaseAddr = (u32)g_adc_dma_buf2;
// DMA_InitStructure.DMA_Memory1BaseAddr = (u32)g_adc_dma_buf2;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 2;//SAMPLE_BUFFER_LEN;
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_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular | DMA_SxCR_DBM;
//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_InitStructure.DMA_Channel = RHEOSTAT_ADC_DMA_CHANNEL;
DMA_Init(RHEOSTAT_ADC_DMA_STREAM, &DMA_InitStructure);
DMA_ITConfig( DMA2_Stream0 , DMA_IT_TC , ENABLE);
DMA_Cmd(RHEOSTAT_ADC_DMA_STREAM, ENABLE);
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_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
//ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
//ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
//---------------------------------------------------------------------------
ADC_Init(RHEOSTAT_ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(RHEOSTAT_ADC1, RHEOSTAT_ADC_CHANNEL1, 1, ADC_SampleTime_3Cycles);
//---------------------------------------------------------------------------
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_Init(RHEOSTAT_ADC2, &ADC_InitStructure);
ADC_RegularChannelConfig(RHEOSTAT_ADC2, RHEOSTAT_ADC_CHANNEL2, 1, ADC_SampleTime_3Cycles);
//---------------------------------------------------------------------------
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
ADC_DMACmd(RHEOSTAT_ADC1, ENABLE);
ADC_Cmd(RHEOSTAT_ADC1, ENABLE);
ADC_Cmd(RHEOSTAT_ADC2, ENABLE);
ADC_SoftwareStartConv(RHEOSTAT_ADC1);
//ADC_SoftwareStartConv(RHEOSTAT_ADC2);
}
int main()
{
gpio_output_init();
Rheostat_Init();
//TIM3_Int_Init(2,42-1);
TIM3_Int_Init(2,42-1);
}