打印
[STM32L1]

STM32L151RDT6多通道ADC+DMA方式,驱动程序没反应,求助。

[复制链接]
1228|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
者结终|  楼主 | 2018-8-28 15:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void AD_Configuration(void)
{
        DMA_InitTypeDef DMA_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
        ADC_InitTypeDef ADC_InitStructure;
       
        /*Enable DMA1 Clock*/
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

        /*DMA1 Channel1 Configuration*/
        DMA_DeInit(DMA1_Channel1);
        DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS;
        DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_ConvertedValue;
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
        DMA_InitStructure.DMA_BufferSize = 2;
        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_MemoryDataSize_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);

        /*ENABLE DMA1 CHANNEL1*/
        DMA_Cmd(DMA1_Channel1, ENABLE);

        /*------------ADC1 configuration with DMA enabled---------*/
        /*Enable the HSI oscillator*/
        RCC_HSICmd(ENABLE);

        /*Enable GPIOA Clock*/
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        /*Check that HSI oscillator is ready*/
        while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
        ADC_DeInit(ADC1);
        ADC_InitStructure.ADC_ScanConvMode = ENABLE;
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
        ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfConversion = 2;
        ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
        ADC_Init(ADC1, &ADC_InitStructure);

        /*ADC1 regular channel10 configuration*/
        ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_48Cycles);
        ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 2, ADC_SampleTime_48Cycles);
       
        ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
       
        //Enable ADC1 DMA
        ADC_DMACmd(ADC1, ENABLE);
       
        //Enable ADC1
        ADC_Cmd(ADC1, ENABLE);

        /*Wait until the ADC1 is ready*/
        while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET);

        /*Start ADC1 Software Conversion*/
        ADC_SoftwareStartConv(ADC1);
}
沙发
sky.sun.zz| | 2018-8-28 15:54 | 只看该作者
没有启动ADC-DMA:
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue, ADCNB);

使用特权

评论回复
板凳
者结终|  楼主 | 2018-8-28 21:19 | 只看该作者
sky.sun.zz 发表于 2018-8-28 15:54
没有启动ADC-DMA:
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue, ADCNB);

用的标准库

使用特权

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

本版积分规则

3

主题

6

帖子

0

粉丝