cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446ZE ADC1 channel 14, 15 don't work

HLiu.6
Associate II

There is a similar open issue in another post. https://community.st.com/s/question/0D53W00000EndiI/stm32g030-adc-issue

My MCU STM32F446 is set to read 9 channels' value by ADC1 with DMA2_Stream4. Settings are as below. Using StdDriver @version V1.8.0, 04-November-2016.

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
 
    DMA_DeInit(DMA2_Stream4);
 
	ADCDMA_InitStructure1.DMA_Channel = DMA_Channel_0;
	ADCDMA_InitStructure1.DMA_PeripheralBaseAddr = ((uint32_t)(&(ADC1->DR)));
	ADCDMA_InitStructure1.DMA_Memory0BaseAddr = (uint32_t)&(adc_monitor_sample_raw_data[0]);
	ADCDMA_InitStructure1.DMA_DIR = DMA_DIR_PeripheralToMemory;
	ADCDMA_InitStructure1.DMA_BufferSize = ADC1_OCCUPY_CHANNEL_AMOUNT;
	ADCDMA_InitStructure1.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	ADCDMA_InitStructure1.DMA_MemoryInc = DMA_MemoryInc_Enable;
	ADCDMA_InitStructure1.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
	ADCDMA_InitStructure1.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	ADCDMA_InitStructure1.DMA_Mode = DMA_Mode_Circular;
	ADCDMA_InitStructure1.DMA_Priority = DMA_Priority_High;
 
	ADCDMA_InitStructure1.DMA_FIFOMode = DMA_FIFOMode_Enable;
	ADCDMA_InitStructure1.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
	ADCDMA_InitStructure1.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	ADCDMA_InitStructure1.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
 
	DMA_Init(DMA2_Stream4, &ADCDMA_InitStructure1);
 
    /* ADC Common Init **********************************************************/
    ADC_CommonInitStructure1.ADC_Mode = ADC_Mode_Independent;
    ADC_CommonInitStructure1.ADC_Prescaler = ADC_Prescaler_Div2;
    ADC_CommonInitStructure1.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
    ADC_CommonInitStructure1.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
    ADC_CommonInit(&ADC_CommonInitStructure1);
 
    /* ADC configuration ------------------------------------------------------*/
    ADC_InitStructure1.ADC_Resolution = ADC_Resolution_12b;
    ADC_InitStructure1.ADC_ScanConvMode = ENABLE;
    ADC_InitStructure1.ADC_ContinuousConvMode = ENABLE;
    ADC_InitStructure1.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
    ADC_InitStructure1.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
    ADC_InitStructure1.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure1.ADC_NbrOfConversion = ADC1_OCCUPY_CHANNEL_AMOUNT;
    ADC_Init(ADC1, &ADC_InitStructure1);
 
    /* ADC regular channel configuration */
    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 7, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 8, ADC_SampleTime_28Cycles);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 9, ADC_SampleTime_28Cycles);
 
	ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
 
	/* Enable ADC and DMA */
	ADC_DMACmd(ADC1, ENABLE);
	ADC_Cmd(ADC1, ENABLE);
	DMA_Cmd(DMA2_Stream4, ENABLE);
 
	/* Start ADC Software Conversion */
	ADC_SoftwareStartConv(ADC1);

The input data from channel 1~9 are quite normal and can auto-update all the time. Channel 14 and 15 can also auto-update but it didn't read the correct voltage. Like even a 3.3V input, its ADC value would still around 300. Check below, the array adc_monitor_sample_raw_data[6], channel 9 is still correct and stable but [7], [8] (channel 14, 15) are not. 

However, a strange thing is I tried with CubeMX, used HAL Driver @1.7.10, called HAL_ADC_Start_DMA() to do the same thing. It worked! But I compared every register bits of ADC, ADC1 and DMA after initialization, no big differences (except some useless interrupt settings because both IRQhandler are not defined) but still don't work. Though after I also configured interrupt and made 100% same as HAL Driver, NO HELP.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> But I compared every register bits of ADC, ADC1 and DMA after initialization, no big differences

How about the GPIO registers? That's a lot of noise. Looks like the pins might not be in analog mode.

Registers don't lie. Gotta be an answer somewhere in there.

> However, a strange thing is I tried with CubeMX, used HAL Driver @1.7.10, called HAL_ADC_Start_DMA() to do the same thing. It worked!

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
HLiu.6
Associate II

0693W00000DlhEvQAJ.png0693W00000DlhH1QAJ.png

TDK
Guru

> But I compared every register bits of ADC, ADC1 and DMA after initialization, no big differences

How about the GPIO registers? That's a lot of noise. Looks like the pins might not be in analog mode.

Registers don't lie. Gotta be an answer somewhere in there.

> However, a strange thing is I tried with CubeMX, used HAL Driver @1.7.10, called HAL_ADC_Start_DMA() to do the same thing. It worked!

If you feel a post has answered your question, please click "Accept as Solution".
HLiu.6
Associate II

Thanks a lot! It is the GPIO setting, I also copied the macro pin name when init GPIO.