cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB ADC not working along with BLE

MichalPesko
Associate II

Hello, I am trying to read battery voltage within a task called by sequencer on STM32WB55CEU.

I am following this post: https://community.st.com/t5/stm32-mcus/how-to-use-the-stm32-adc-s-internal-reference-voltage/ta-p/621425

I verified that I can measure both VREFint and Channel 10 separately in Single Mode, however combining 2 measurements in Scan mode does not work. I am not sure whats causing this, considering I am doing everything as recommended in the provided post. It may not be related to BLE. I must be missing something obvious.

In the following code, the call to 

 

/*
	 * Rank 2: measurement channel
	 */
	stat = HAL_ADC_PollForConversion(&hadc1, 0xffff);
	uint32_t measurement_raw = HAL_ADC_GetValue(&hadc1);

 

takes about 10 seconds and measurement_raw becomes same value as vrefint_raw. The Vrefint conversion seems ok.

This is the whole code:

 

void ADC_BattMonitor_Init(void) {

	  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

	  __NOP();

}


float ADC_BattMonitor_GetVoltage(void) {

	HAL_StatusTypeDef stat;

	stat = HAL_ADC_Start(&hadc1);

	/*
	 * Rank 1: vref internal
	 */
	stat = HAL_ADC_PollForConversion(&hadc1, 0xffff);
	uint32_t vrefint_raw = HAL_ADC_GetValue(&hadc1);


	/*
	 * Rank 2: measurement channel
	 */
	stat = HAL_ADC_PollForConversion(&hadc1, 0xffff);
	uint32_t measurement_raw = HAL_ADC_GetValue(&hadc1);

	/*
	 * This macro calculates the vdda voltage (as a uint32_t representing the voltage in milliVolts)
	 * using the vref internal raw adc value, and the internal calibration value in ROM
	 */
	uint32_t vdda_voltage = __HAL_ADC_CALC_VREFANALOG_VOLTAGE(vrefint_raw, ADC_RESOLUTION_12B);


	/*
	 * A helper function for doing a raw ADC value to voltage conversion, essentially
	 *
	 * vdda_voltage * measurement_raw / 2^12
	 *
	 */
	uint32_t measurement_voltage = __HAL_ADC_CALC_DATA_TO_VOLTAGE(vdda_voltage, measurement_raw, ADC_RESOLUTION_12B);


	stat = HAL_ADC_Stop(&hadc1);

	return 0.0f;

}

 

This is CubeMX config, channel 10 and Vrefint enabled:

mx1.png

a4d5ed2f-c2e3-47ee-b054-d171b82f8b44.png

mx2.png

 

1 REPLY 1
STTwo-32
ST Employee

Hello @MichalPesko 

Are you testing the same behavior when the BLE is not active? If no, ensure that you are implementing on the right way the task of the ADC conversation on the application sequencer. 

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.