2022-03-20 11:20 AM
Source:
int main(void)
{
HAL_Init();
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2) != HAL_OK)
{
Error_Handler();
}
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.NbrOfDiscConversion = 1;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc1);
while (1)
{
}
}
Solved! Go to Solution.
2022-03-21 7:13 AM
2022-03-20 3:29 PM
Against which point do you measure? What is VSSA/VREF- voltage/change against that point?
JW
2022-03-21 1:31 AM
Thank you waclawek.jan for the fast answer! I measure VDDA against GND, VSS and VSSA is bound to GND.
2022-03-21 3:42 AM
In real world, there are real resistances between different points of the same conductor.
Measure VSSA against the same point you called GND. Is there any voltage jump associated with switching on the ADC?
JW
2022-03-21 4:42 AM
VSSA is at VSS and GND level. The problem is that the VDDA output of the STM32L431RCI is driving the linear voltage regulator (TPS7A02) output from 1.85V up to 1.94V.
The same is happening on the NUCLEO STM32L433RC-P board with external VDDA at 1.8V (desoldered SB78) but it is pushed up to 2.4V. So why is current flowing from the VDDA input to the linear voltage regulator output, as soon as the ADC is enabled?
2022-03-21 7:13 AM
Do you have SYSCFG_CFGR1.BOOSTEN switched on?
JW
2022-03-21 7:27 AM
No it is not enabled! I guess that was the problem, as stated in the reference manual:After I set the BOOSTEN bit the voltage dropped back down to 1.85V.
Thank you very much waclawek.jan you solved it!! :)
2022-03-22 12:25 AM
For completeness if someone has the same problem...
The limitation is mentioned in the device errata (ES0320-Rev6, Page 9):
With the workarround:
2022-03-22 2:57 AM
Thanks for that detail.
JW