2021-11-17 01:14 AM
I am STM32L422 to measure ADC using internal reference voltage.
My code is generated using CubeMX V6.2.
I want to measure ADC from ADC1_IN1 using PA7.
The data sheet says internal voltage is 1.2 V. Reading VREFINT register gave value 1658 which is 1.214 V from 3v full scale.
My maximum voltage input is 3V. It is connected to ADC in through 20k/10k voltage divider.
3V *10/30 = 1V
But I get 0.595 V.
If Vref = 1.2, then I should get 1.2 V in Vref pin but Vref pin voltage is 0.535 volt.
To enable internal reference voltage, I have checked Vrefint Channel in ADC
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_SPI1_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_TIM6_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
// =======================================================================================================
printf("VREFINT: %ud\n", VREFINT);
while(HAL_ADCEx_Calibration_Start(&hadc1,0) != HAL_OK);
// =======================================================================================================
printf("Battery Voltage Check ...\n");
HAL_Delay(100);
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,100);
ADC_Val=HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
float Result = (float)((1.200 * ADC_Val) / 4095);
printf("Digital: %d, Result Value : %f \r\n", ADC_Val, Result );
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
;
}
}
My initialization code is generated using CubeMX V6.2.
What is the problem here ?
2021-11-17 05:18 AM
> If Vref = 1.2, then I should get 1.2 V in Vref pin but Vref pin voltage is 0.535 volt.
What "Vref pin"?
There is no separate VREF+ pin on 'L422KBTx, it's connected to VDDA which you are supposed to connect to analog supply voltage. (The only 'L422 with separate VREF+ pin is in WLCSP36 package).
Also, in 'L42x, there is no VREFBUF module i.e. you can't output the internal reference voltage.
JW