打印
[STM32F4]

大家帮忙看看我的dma传输

[复制链接]
678|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
bingshiliuxing|  楼主 | 2015-11-26 10:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
DMA, AD, ADC, dc, ni
我用STM32F401的adc1采样一个通道数据,然后通过dma传输到存储器,但是程序一直显示adc溢出,并且dma无动作,我查看dma的寄存器,显示都是0,似乎配置都没有写进寄存器,不知道哪里的问题,请大神帮忙看下,小弟不胜感激

#define ADC1_DR_Address  ((uint32_t)0X4001204C)

void DMA_Config(void)
{
                DMA_InitTypeDef DMA_InitStruct;
       
                RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2,ENABLE);

                DMA_DeInit(DMA2_Stream0);
                DMA_InitStruct.DMA_BufferSize=10;
                DMA_InitStruct.DMA_Channel=DMA_Channel_0;
                DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralToMemory;
                DMA_InitStruct.DMA_FIFOMode=DMA_FIFOMode_Disable;
                DMA_InitStruct.DMA_FIFOThreshold=DMA_FIFOThreshold_HalfFull;
                DMA_InitStruct.DMA_Memory0BaseAddr=(uint32_t)&adc_buff[0];
                DMA_InitStruct.DMA_MemoryBurst=DMA_MemoryBurst_Single;
                DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
                DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Enable;
                DMA_InitStruct.DMA_Mode=DMA_Mode_Circular;
                DMA_InitStruct.DMA_PeripheralBaseAddr=/*(uint32_t)(ADC1_BASE+0x4C);*/ADC1_DR_Address;
                DMA_InitStruct.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
                DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
                DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
                DMA_InitStruct.DMA_Priority=DMA_Priority_High;
       
                DMA_Init(DMA2_Stream0,&DMA_InitStruct);
                DMA_Cmd(DMA2_Stream0,ENABLE);
}
void adc_init(void)
{
                GPIO_InitTypeDef GPIO_SET;               //GPIO config
                ADC_InitTypeDef ADC_InitStruct;
                ADC_CommonInitTypeDef ADC_CommonInitStruct;
       
                GPIO_SET.GPIO_Mode=GPIO_Mode_AN;         //Analog mode
                GPIO_SET.GPIO_Speed=GPIO_Speed_100MHz;    //Max speed is 50M
                GPIO_SET.GPIO_OType=GPIO_OType_OD;       //Open drain output
                GPIO_SET.GPIO_PuPd=GPIO_PuPd_NOPULL;     //Pull no
                GPIO_SET.GPIO_Pin=GPIO_Pin_1;
                GPIO_Init(GPIOA, &GPIO_SET);             //Init GPIO

                RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
       
                ADC_DeInit();

                ADC_CommonInitStruct.ADC_DMAAccessMode=ADC_DMAAccessMode_1;
                ADC_CommonInitStruct.ADC_Mode=ADC_Mode_Independent;
                ADC_CommonInitStruct.ADC_Prescaler=ADC_Prescaler_Div2;
                ADC_CommonInitStruct.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_5Cycles;
       
                ADC_CommonInit(&ADC_CommonInitStruct);       
       
                ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;
                ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
                ADC_InitStruct.ADC_ExternalTrigConv=ADC_ExternalTrigConvEdge_None;
                ADC_InitStruct.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
                ADC_InitStruct.ADC_NbrOfConversion=1;
                ADC_InitStruct.ADC_Resolution=ADC_Resolution_12b;
                ADC_InitStruct.ADC_ScanConvMode=ENABLE;
       
                ADC_Init(ADC1,&ADC_InitStruct);

                ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_15Cycles);

          ADC_DMARequestAfterLastTransferCmd(ADC1,DISABLE);
                ADC_DMACmd(ADC1,ENABLE);

                ADC_Cmd(ADC1,ENABLE);
               
                DMA_Config();
                adc_delay(20000);
                ADC_SoftwareStartConv(ADC1);

}


沙发
bingshiliuxing|  楼主 | 2015-11-26 10:44 | 只看该作者
自己帮忙顶下,adc本来应该连续采样的,可是只能采样一个数据,然后就溢出停到那了,各路大神帮帮忙

使用特权

评论回复
板凳
bingshiliuxing|  楼主 | 2015-11-26 15:46 | 只看该作者
DMA上面的那句时钟使能写错了,写成了复位,改过之后DMA寄存器正确了,可是还是不能传输,并且ADC依然只采样一次就显示溢出。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

4

帖子

1

粉丝