2025-05-13 6:59 AM - edited 2025-05-13 7:00 AM
Hello.
I have a problem with the ADC on the custom board with the STM32WB55 chip. I am using a divider and should get something around 2V, but I always get the maximum value - 4095.
I am using this code that I saw in the ST examples.
HAL_GPIO_WritePin(ADC_OUT_GPIO_Port, ADC_OUT_Pin, GPIO_PIN_SET);
HAL_Delay(50);
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
if (HAL_ADC_Start_DMA(&hadc1, (uint32_t*)aADCxConvertedData, BATTERY_ARRAY_SIZE) != HAL_OK) {
HAL_GPIO_WritePin(ADC_OUT_GPIO_Port, ADC_OUT_Pin, GPIO_PIN_RESET);
Error_Handler();
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
if(hadc->Instance == ADC1) {
if (HAL_ADC_Stop_DMA(&hadc1) != HAL_OK) {
Error_Handler();
}
HAL_GPIO_WritePin(ADC_OUT_GPIO_Port, ADC_OUT_Pin, GPIO_PIN_RESET);
uint32_t sum_mv = 0;
for (uint32_t i = 0; i < BATTERY_ARRAY_SIZE; i++) {
aADCxConvertedData_Voltage_mVolt[i] = __ADC_CALC_DATA_VOLTAGE(VDDA_APPLI, aADCxConvertedData[i]);
sum_mv += aADCxConvertedData_Voltage_mVolt[i];
}
uint16_t avg_mv = sum_mv / BATTERY_ARRAY_SIZE;
ubDmaTransferStatus = 1;
}
}
I put a breakpoint on ubDmaTransferStatus and see what it measures.
I use this same code on the nucleo board by shorting PC1 and PC0 with a wire and seeing normal results, around 3294-3296 mV.
This is not a hardware problem, I measured the output of the divider on the pin with an oscilloscope and saw around 2V. I also tested it on two devices.
I attach a project that works with nucleo, maybe this will help somehow.
Please help me.
Regards.
2025-05-13 7:15 AM
Step through the program in debug mode and see where it goes wrong.
2025-05-13 7:17 AM
@IlliaGx wrote:custom board with the STM32WB55 chip..
It's a custom board - so you need to show the schematic.
How to write your question to maximize your chances to find a solution
2025-05-13 7:57 AM
2025-05-13 8:06 AM
You need to show the full schematic!
2025-05-13 8:08 AM
Hello. Thank you for your answer.
Could you please tell me what I should be looking at? I am already looking at the result in the HAL_ADC_ConvCpltCallback completion callback
2025-05-13 8:12 AM
Thanks for the reply.
This is the fragment of the schematic that deals with this issue. Everything else is fine, I've asked questions about this device in past threads, and everything worked just like the nucleo.
Regards.
2025-05-13 8:19 AM
> Everything else is fine
Clearly this is not the case.
My crystal ball says VREF+ is not fine.
2025-05-13 9:16 AM
Thanks for the reply!
It's internally connected to the VDDA.
Regards
2025-05-13 9:52 AM
> It's internally connected to the VDDA.
It is not internally connected to VDDA, it is a distinct pin and must be powered.
That is the root of your issues.
Your options are: