We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, I am trying to implement multi-channel adc with dma. I am using STM32F746 Discovery Board. But seems not working. Here is my initialization functions :
First, here is my buffer that fills with ADC Channels data.
// TOTAL_TRANSFER_WORDS is defined as ((ADC_CHANNEL_COUNT) * (MOVING_AVERAGE_WINDOW_SIZE)) // and ADC_CHANNEL_COUNT defined as 5, als MOVING_AVERAGE_WINDOW_SIZE defined as 10. uint16_t volatile total_adc_readings[TOTAL_TRANSFER_WORDS] = { 0x00 };
static void adc_initialization(void) { ADC_HandleTypeDef adc_handle; ADC_ChannelConfTypeDef sConfig; // USED_ADC is actually ADC3 adc_handle.Instance = USED_ADC; adc_handle.Init.Resolution = ADC_RESOLUTION_12B; adc_handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8; adc_handle.Init.ScanConvMode = ADC_SCAN_ENABLE; adc_handle.Init.ContinuousConvMode = ENABLE; adc_handle.Init.DiscontinuousConvMode = DISABLE; adc_handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; adc_handle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; adc_handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; adc_handle.Init.DMAContinuousRequests = ENABLE; adc_handle.Init.NbrOfDiscConversion = 0; adc_handle.Init.NbrOfConversion = ADC_CHANNEL_COUNT; if ( HAL_ADC_Init(&adc_handle) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // Common channel configurations sConfig.Offset = 0; sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; // channel 0 configurations sConfig.Rank = 1; // SYSTEM_SUPPLY_CHANNEL is actually ADC_CHANNEL_4 sConfig.Channel = SYSTEM_SUPPLY_CHANNEL; if ( HAL_ADC_ConfigChannel(&adc_handle, &sConfig) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // channel 1 configurations sConfig.Rank = 2; // EXT_BAT_SUPPLY_CHANNEL is actually ADC_CHANNEL_5 sConfig.Channel = EXT_BAT_SUPPLY_CHANNEL; if ( HAL_ADC_ConfigChannel(&adc_handle, &sConfig) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // channel 2 configurations sConfig.Rank = 3; // MAIN_BAT_SUPPLY_CHANNEL is actually ADC_CHANNEL_6 sConfig.Channel = MAIN_BAT_SUPPLY_CHANNEL; if ( HAL_ADC_ConfigChannel(&adc_handle, &sConfig) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // channel 3 configurations sConfig.Rank = 4; // this is used for internal temperature sensor. sConfig.Channel = ADC_CHANNEL_13; if ( HAL_ADC_ConfigChannel(&adc_handle, &sConfig) ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // channel 18 configurations sConfig.Rank = 5; // RC_BAT_SUPPLY_CHANNEL is actually ADC_CHANNEL_7 sConfig.Channel = RC_BAT_SUPPLY_CHANNEL; if ( HAL_ADC_ConfigChannel(&adc_handle, &sConfig) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } // start dma transfer if ( HAL_ADC_Start_DMA(&adc_handle, (uint32_t*)&total_adc_readings, TOTAL_TRANSFER_WORDS) != HAL_OK ) { while ( 1 ) { /* ADC INITIALIZATION FAILED */ } } }
And here is my msp init function :
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStructure; static DMA_HandleTypeDef hdma_adc; // Enable GPIO Clock, ADC Clock, DMA2 Clock respectively ADC_GPIO_PORT_CLK_ENABLE(); // this is actually __HAL_RCC_GPIOF_CLK_ENABLE() ADC_CLK_ENABLE(); // this is actually __HAL_RCC_ADC3_CLK_ENABLE() DMA_CLK_ENABLE(); // this is actually __HAL_RCC_DMA2_CLK_ENABLE() // Configure ADC Pins // VSYS_LEVEL_ADC_PIN is actually GPIO_PIN_6 // VBAT_EXT_LEVEL_ADC_PIN is actually GPIO_PIN_7 // VBAT_MAIN_LEVEL_ADC_PIN is actually GPIO_PIN_8 // VBAT_RC_LEVEL_ADC_PIN is actually GPIO_PIN9 // and lastly ADC_GPIO_PORT is actually GPIOF GPIO_InitStructure.Pin = ( VSYS_LEVEL_ADC_PIN | VBAT_EXT_LEVEL_ADC_PIN | VBAT_MAIN_LEVEL_ADC_PIN | VBAT_RC_LEVEL_ADC_PIN ); GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; GPIO_InitStructure.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADC_GPIO_PORT, &GPIO_InitStructure); // Configure DMA Streams // ADC_DMA_STREAM is actually DMA2_Stream0 // and lastly ADC_DMA_CHANNEL is DMA_CHANNEL_2 hdma_adc.Instance = ADC_DMA_STREAM; hdma_adc.Init.Channel = ADC_DMA_CHANNEL; hdma_adc.Init.Mode = DMA_CIRCULAR; hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc.Init.MemInc = DMA_MINC_ENABLE; hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc.Init.Priority = DMA_PRIORITY_HIGH; hdma_adc.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; hdma_adc.Init.MemBurst = DMA_MBURST_SINGLE; hdma_adc.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_adc); /* Associate the initialized DMA handle to the ADC handle */ __HAL_LINKDMA(hadc, DMA_Handle, hdma_adc); }
after all, when I debugging the code, total_adc_readings is always filled with 0x00. It means that, ADC initialization is false I think.
But I can not find the problem with the initialization code. Could you help me for finding problem in the initialization code. Thanks for answers. Best regards.