芯片是MM32F3277
用DMA读取ADC中的数据。现在可以进入DMA中断,但调试器中AD_value一直没有值。求大佬指点一下。
#include "DMA_ADC.h"
uint16_t AD_value[10]; //ADC采样的数据经过DMA传输的数据放在这里
unsigned short LI_ADCflag=0;
//ADC I/O口初始化
void LI_ADC_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphclockCmd(RCC_AHBENR_GPIOA|RCC_AHBENR_GPIOB,ENABLE); //使能ADC I/O时钟
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4; //通道引脚
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN; //电平输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void LI_DMA_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); //DMA1时钟使能
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&(ADC1->ADDATA); //ADC数据寄存器地址作为源
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&AD_value; //将ADC中的数据转移道AD_value中
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC; //数据传输方向,外设作为源
DMA_InitStructure.DMA_BufferSize=10; //传输数据
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable; //外设地址固定
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable; //内存地址自增
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord; //半字
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular; //循环传输
DMA_InitStructure.DMA_Priority=DMA_Priority_High; //通道优先级为最高级
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable; //禁止内存到内存传输
DMA_Init(DMA1_Channel1,&DMA_InitStructure);
DMA_Cmd(DMA1_Channel1,ENABLE); //DMA通道1使能
DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE); //DMA中断配置
NVIC_InitStruct.NVIC_IRQChannel =DMA1_Channel1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void LI_ADC_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); //使能ADC1的时钟
ADC_InitStructure.ADC_Mode=ADC_Mode_Continuous_Scan; //连续扫描
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; //数据右对齐
ADC_InitStructure.ADC_Resolution=ADC_Resolution_12b; //分辨率12
ADC_InitStructure.ADC_PRESCARE=ADC_PCLK2_PRESCARE_8; //时钟分频8
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T1_CC1;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4,0, ADC_SampleTime_239_5Cycles);
ADC_DMACmd(ADC1,ENABLE); //向DMA发出请求
ADC_Cmd(ADC1,ENABLE);
}
void DMA1_Channel1_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_IT_TC1)!=RESET)
{
DMA_ClearITPendingBit(DMA1_IT_TC1);
ADC_SoftwareStartConvCmd(ADC1, DISABLE); //DMA传输20个数据完成,标志置1
LI_ADCflag = 1;
LED_Ctrl(LEDALL,RVS); //LED翻转闪烁
delayms(200);
}
} |