STM32 ADC3 DMA一直没有数据

2020-01-01 17:53发布

使用的是ADC_CH0,DMA_CH1,ADC3_CH1,DMA2_CH5,前者没有问题,后者一直没有数据。
初始化程序如下:
void adc_Init(void)
{
        //RCC_ClocksTypeDef clks;
        //ADC1 + DMA
        /*ADC1/2/3 channel0 PA0 ADC1/2/3 channel1 PA1*/
        RCC_ADCCLKConfig(RCC_PCLK2_Div6); /*72Mhz/6 = 12Mhz*/
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_DMA2, ENABLE);
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;   
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        //DMA Config
        DMA_InitTypeDef DMA_InitStructure;
        DMA_DeInit(DMA1_Channel1);
        DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001244C; //ADC1的DR地址
        DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_ConvertedValue; //不加&应该也可以 数组名 代表地址
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//外设向内存传数据
        DMA_InitStructure.DMA_BufferSize = DMA_C * DMA_N; //DMA缓存大小 //2 * 1024
        DMA_InitStructure.DMA_PeripheralInc = DMA_MemoryInc_Disable;
        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //目标内存地址自动后移
        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//DMA传送数据尺寸16位
        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_Init(DMA1_Channel1, &DMA_InitStructure);
        //ADC Config
        ADC_InitTypeDef ADC_InitStructure;
        ADC_DeInit(ADC1);
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;        //!!
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;        //!!
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = DMA_C; //2
        ADC_Init(ADC1, &ADC_InitStructure);
        ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_1Cycles5); //9Mhz/(239.5 + 12.5) = 35.7Khz
        //ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_1Cycles5); //9Mhz/(239.5 + 12.5) = 35.7Khz
        //ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
        //ADC_ExternalTrigConvCmd(ADC1, DISABLE);
        ADC_DMACmd(ADC1,ENABLE);
        ADC_Cmd(ADC1, ENABLE);
        ADC_ResetCalibration(ADC1);
        while (ADC_GetResetCalibrationStatus(ADC1));
        ADC_StartCalibration(ADC1);
        while (ADC_GetCalibrationStatus(ADC1));
        //ADC_SoftwareStartConvCmd(ADC1, ENABLE);
        ADC_SoftwareStartConvCmd(ADC1, DISABLE);
       
        //ADC2 + NO_DMA
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
        ADC_DeInit(ADC2);
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;        //!!
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;        //!!
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = DMA_C; //2
        ADC_Init(ADC2, &ADC_InitStructure);
        ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5); //12Mhz/(239.5 + 12.5) = 35.7Khz
        //ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
        //ADC_ExternalTrigConvCmd(ADC1, DISABLE);
        ADC_DMACmd(ADC2,ENABLE);
        ADC_Cmd(ADC2, ENABLE);
        ADC_ResetCalibration(ADC2);
        while (ADC_GetResetCalibrationStatus(ADC2));
        ADC_StartCalibration(ADC2);
        while (ADC_GetCalibrationStatus(ADC2));
        ADC_SoftwareStartConvCmd(ADC2, DISABLE);
        //ADC_ExternalTrigConvCmd(ADC2, DISABLE);
        //ADC3 + DMA
        DMA_DeInit(DMA2_Channel5);
        DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40013C4C;
        DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_ConvertedValue_temp;
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
        DMA_InitStructure.DMA_BufferSize = DMA_C * DMA_N;
        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_High;
        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
        DMA_Init(DMA2_Channel5, &DMA_InitStructure);  
        /* Enable DMA2 channel5 */
        DMA_Cmd(DMA2_Channel5, ENABLE);
        RCC_ClocksTypeDef clks;       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
        ADC_DeInit(ADC3);
        ADC_StructInit(&ADC_InitStructure);
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;        //!!
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;        //!!
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = DMA_C; //2
        ADC_Init(ADC3, &ADC_InitStructure);
        ADC_RegularChannelConfig(ADC3, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5); //12Mhz/(239.5 + 12.5) = 35.7Khz
        //ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
        //ADC_ExternalTrigConvCmd(ADC1, DISABLE);
        ADC_DMACmd(ADC3,ENABLE);
        ADC_Cmd(ADC3, ENABLE);
        ADC_ResetCalibration(ADC3);
        while (ADC_GetResetCalibrationStatus(ADC3));
        ADC_StartCalibration(ADC3);
        while (ADC_GetCalibrationStatus(ADC3));
        ADC_SoftwareStartConvCmd(ADC3, DISABLE);
        //ADC_ExternalTrigConvCmd(ADC2, DISABLE);
        RCC_GetClocksFreq(&clks);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。