cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U585 ADC

qqAnton
Senior

Hi,

I have a custom board with STM575VGT6 then we decided to make it smaller and move to STM32U585OI MCU.

On the second board with new MCU, almost all peripherals works fine (DAC, UART, I2C) with almost no code changes, except new MCU defines, drivers etc.

But we have troubles with ADC, it acts very strange. So I decided to write a simple code to test ADC.

void MX_ADC1_Init(void) {
    /* USER CODE BEGIN ADC1_Init 0 */

    /* USER CODE END ADC1_Init 0 */

    ADC_ChannelConfTypeDef sConfig = {0};
    HAL_PWREx_EnableVddA();
    __HAL_RCC_PWR_CLK_ENABLE();

    HAL_PWREx_EnableVddA();
    HAL_PWREx_EnableVddIO2();

    /* USER CODE BEGIN ADC1_Init 1 */

    /* USER CODE END ADC1_Init 1 */

    /** Common config
  */
    hadc1.Instance = ADC1;
    hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV256;
    hadc1.Init.Resolution = ADC_RESOLUTION_14B;
    hadc1.Init.GainCompensation = 0;
    hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
    hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    hadc1.Init.LowPowerAutoWait = DISABLE;
    hadc1.Init.ContinuousConvMode = ENABLE;
    hadc1.Init.NbrOfConversion = 1;
    hadc1.Init.DiscontinuousConvMode = DISABLE;
    hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
    hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
    hadc1.Init.DMAContinuousRequests = DISABLE;
    hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
    hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
    hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
    hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
    hadc1.Init.OversamplingMode = DISABLE;
    if(HAL_ADC_Init(&hadc1) != HAL_OK) {
        Error_Handler();
    }

    /** Configure Regular Channel
  */
    sConfig.Channel = ADC_CHANNEL_7;
    sConfig.Rank = ADC_REGULAR_RANK_1;
    sConfig.SamplingTime = ADC_SAMPLETIME_36CYCLES;
    sConfig.SingleDiff = ADC_SINGLE_ENDED;
    sConfig.OffsetNumber = ADC_OFFSET_NONE;
    sConfig.Offset = 0;
    if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
        Error_Handler();
    }
    /* USER CODE BEGIN ADC1_Init 2 */
    if(HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK) {
        Error_Handler();
    }

    if(HAL_ADC_Start(&hadc1) != HAL_OK) {
        Error_Handler();
    }
    /* USER CODE END ADC1_Init 2 */
}

void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) {
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    if(adcHandle->Instance == ADC1) {
        /* USER CODE BEGIN ADC1_MspInit 0 */

        /* USER CODE END ADC1_MspInit 0 */

        /** Initializes the peripherals clock
  */
        PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
        PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_SYSCLK;
        if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
            Error_Handler();
        }

        /* ADC1 clock enable */
        __HAL_RCC_ADC12_CLK_ENABLE();

        __HAL_RCC_GPIOA_CLK_ENABLE();
        /**ADC1 GPIO Configuration
    PA0     ------> ADC1_IN5
    PA2     ------> ADC1_IN7
    PA3     ------> ADC1_IN8
    PA6     ------> ADC1_IN11
    */
        GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7;
        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

        GPIO_InitStruct.Pin = GPIO_PIN_1;
        GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/*
//main loop code
        adc_st = HAL_ADC_PollForConversion(&hadc1, 1000);
        if(adc_st != HAL_OK) {
            //Error_Handler();
            SEGGER_RTT_printf(0, "adc err %u\r\n", adc_st);
        }
        uhADCxConvertedData = HAL_ADC_GetValue(&hadc1);
        vTaskDelay(500);
*/

1. When nothing is connected, it shows 3.3V

2. When I conned it to some signal source, It shows 0 up to 2.5 V, then start to show some strange values from 0 to 3.3V

3. When signal is 3V and more, it shows 3.3V

 

About the schematic, VREF+ and VDDA is connected to 3.3V.

    __HAL_RCC_VREF_CLK_ENABLE();
    HAL_SYSCFG_DisableVREFBUF();
    HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE);

 

Whats is also strange, 

ADC_CHANNEL_VBAT is also showing 3.3V, but should be 0.8V.
 
I need help to understand, is it schematic/board problem or it could be solved by code.
 
Thank you,
Anton

 

1 REPLY 1
TDK
Super User

> STM575VGT6 

No such chip. STM32U575VGT6 maybe?

 

Most likely a hardware problem. Sounds like current is leaking somewhere. Perhaps VREF+ is not stable, being pulled down, or not connected well. If you have the ability to x-ray the board to verify solder connections, I'd do that, especially around VREF/VDDA/VSSA.

 

Do you have just one of these boards or multiple? Do they all behave the same?

 

Also wouldn't hurt to show the schematic, if you can.

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