以下是配置部分: ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable ADC3, DMA2 and GPIO clocks ****************************************/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* DMA2 Stream0 channel2 configuration **************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_DMA1, ENABLE); __nop(); //等待 DMA2 时钟稳定 __nop(); //经测试最少 2 个 nop DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; 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_VeryHigh; 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); DMA_Cmd(DMA2_Stream0, ENABLE); /* DMA中断开 */ // DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE); /* Configure ADC1 Channel7 pin as analog input ******************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* ADC3 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b; 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_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC Common Init **********************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles; ADC_CommonInit(&ADC_CommonInitStructure); // ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); //使能ADC转换结束中断 // ADC_ITConfig(ADC1, ADC_IT_OVR, ENABLE); // /*********************ADC看门狗配置***************************/ // ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable); // ADC_AnalogWatchdogThresholdsConfig(ADC3, 0x0E8B, 0x0555); //阈值设置。高:3V 低:1V // ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_7); // ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* ADC3 regular channel7 configuration *************************************/ ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_144Cycles); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); /* Enable ADC3 DMA */ ADC_DMACmd(ADC1, ENABLE); // ADC_ContinuousModeCmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); 问题:直接读取ADC1ConvertedValue值,始终为0,结果不随AD输入改变。而用ADC_GetConversionValue(ADC1)函数读取采样值,结果又是对的,能说明AD转换这块没错吧,DMA传输不正确,到底哪错了???求大神赐教!谢谢 |
RE:有关ADC-DMA配置问题
2、你是否设置了DMA的中断优先级呢?
3、你的DMA中断函数代码贴上看看
RE:有关ADC-DMA配置问题
RE:有关ADC-DMA配置问题
RE:有关ADC-DMA配置问题
1、时钟是否正确;??
2、DMA与AD的映射是否正确;
3、DMA中断是否有触发,有没有打过点;
RE:有关ADC-DMA配置问题
回复:有关ADC-DMA配置问题
DMA.txt
2014-1-2 09:27 上传
点击文件名下载附件
1.92 KB, 下载次数: 15
DMA_h.txt
2014-1-2 09:27 上传
点击文件名下载附件
164 Bytes, 下载次数: 6
回复:有关ADC-DMA配置问题
1、检查 ADC1_DR_ADDRESS的地址是否正确
2、你是否设置了DMA的中断优先级呢?
3、你的DMA中断函数代码贴上看看
ADC1_DR_ADDRESS的地址为0X4001244C,没错吧。
中断优先级函数如下:
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* ADC中断配置 */
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; //嵌套通道为ADC_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7; //响应优先级为 2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);
/* Enable the DMA7 Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 8;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA中断函数如下:
void DMA2_Stream0_IRQHandler(void)
{
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
{
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
}
}
需要哪些处理,在这里不懂诶???求指教!谢谢
回复:有关ADC-DMA配置问题
给你看看这个能用的。
好的,谢谢
回复:有关ADC-DMA配置问题
可以断定ADC肯定没有问题
1、时钟是否正确;??
2、DMA与AD的映射是否正确;
3、DMA中断是否有触发,有没有打过点;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);这条语句时能了时钟就可以了吗???
映射我查过了,ADC1映射到DMA的Stream0的第0通道,代码也没错的。
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);这条语句我时能了传输完成中断,调试的时候确实能进中断的。
void DMA2_Stream0_IRQHandler(void)
{
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
{
// DMA_Cmd(DMA2_Stream0, DISABLE);
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
printf("!! \r\n");
}
}
是用printf("!! \r\n");语句用串口显示判断的。