代码如下。
代码如下。
/******************************************************************************
* Function Name: ADC_DMA_Config
* Description: DMA配置
* Input:
* Output:
* Return:
******************************************************************************/
void ADC_DMA_Config3(void)
{
// DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
DMA_DeInit(DMA2_Channel5);
// DMA_StructInit(&DMA_InitStructure_ADC3);
DMA_InitStructure_ADC3.DMA_PeripheralBaseAddr = (uint32_t)&(ADC3->DR); //外设首地址ADC1_BASE+0x4C ADC1_CDRADC3_4->CDR
DMA_InitStructure_ADC3.DMA_MemoryBaseAddr = (uint32_t)&ADC_ConvertedValue_NO3; //自己定义的存储区
DMA_InitStructure_ADC3.DMA_DIR = DMA_DIR_PeripheralSRC; //数据传输外设到内存
DMA_InitStructure_ADC3.DMA_BufferSize = ADCOUTNBUFFLENGTH;//数据大小12
DMA_InitStructure_ADC3.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址寄存器地址自动增加地址禁止
DMA_InitStructure_ADC3.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址自动增加
DMA_InitStructure_ADC3.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //外设数据大小
DMA_InitStructure_ADC3.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord; //内存数据大小,同上
DMA_InitStructure_ADC3.DMA_Mode = DMA_Mode_Circular; //DMA循环传输
DMA_InitStructure_ADC3.DMA_Priority = DMA_Priority_High; //高优先级
// DMA_DoubleBufferModeConfig(DMA2_Stream0, (uint32_t)ADC_ConvertedValue_NO2, DMA_Memory_1);
// DMA_DoubleBufferModeCmd(DMA2_Stream0, ENABLE);
DMA_Init(DMA2_Channel5, &DMA_InitStructure_ADC3);
DMA_Cmd(DMA2_Channel5, ENABLE); //使能DMA2_Stream0??
// DMA_ITConfig(DMA2_Channel5, DMA_IT_TC, ENABLE);
}
void ADC_Config3(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC34, ENABLE);
//添加一步初始化
ADC_DeInit(ADC3);
// ADC_StructInit(&ADC_InitStructure);
// ADC_CommonStructInit(&ADC_CommonInitStructure);
//
/* Calibration procedure */
ADC_VoltageRegulatorCmd(ADC3, ENABLE);
/* Insert delay equal to 10 */
DelayUS(10);
ADC_SelectCalibrationMode(ADC3, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC3);
while(ADC_GetCalibrationStatus(ADC3) != RESET );
calibration_value = ADC_GetCalibrationValue(ADC3);
// ADC_InitStructure.ADC_AutoInjMode =
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
ADC_InitStructure.ADC_NbrOfRegChannel = 6;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_Init(ADC3, &ADC_InitStructure);
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent ;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 5;
ADC_CommonInit(ADC3,&ADC_CommonInitStructure);
/* ADC1 Regular Channel1 Configuration */
ADC_RegularChannelConfig(ADC3, ADC_Channel_2, 1, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 2, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 3, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_14, 4, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_15, 5, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC3, ADC_Channel_16, 6, ADC_SampleTime_7Cycles5);//ADC_SampleTime_55Cycles5);
ADC_DMA_Config3();
ADC_DMAConfig(ADC3,ADC_DMAMode_Circular);
ADC_DMACmd(ADC3, ENABLE); /* Enable ADC1's DMA interface */
/* Enable ADC2 external trigger conversion */
// ADC_ExternalTrigConvCmd(ADC4, ENABLE);
ADC_Cmd(ADC3, ENABLE); /* Enable ADC1 */
// /* Start ADC1 calibaration */
ADC_StartCalibration(ADC3);
////// /* Check the end of ADC1 calibration */
//////// while(ADC_GetCalibrationStatus(ADC4));
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_RDY));
ADC_StartConversion(ADC3);/* Start ADC1 Software Conversion*/
//ADC_StopConversion(ADC4);
}
结果数据只能拿到6个,我的ADCDMABUFF大小是12
数据时6个0xDBE6之类的数据,长度和数据都不对,ADC3->DR寄存器数据测试是对的。就是传到DMA的ADC_ConvertedValue_NO3数组不对了。调试了很久,时钟也是打开了,网上F303的资料太少,不知道错误出在哪里。芯片是STM32F303VC。看看论坛中的高手能否相助,或者提供点思路。
这个代码,带入到ADC2 ,ADC4中,测试,全是对的。唯独在ADC3这个上出问题。ADC3寄存器数据读取出来是对的。DMA过来就出问题了。 |
|