Skip to main content
Associate
September 16, 2024
Solved

STM32CubeIDE Voltage Sensor with STM32F103C8T6

  • September 16, 2024
  • 4 replies
  • 1692 views

The is voltage sensing in live expression I'm using STM32F103C8T6 board popularly known as blue pill im using a voltage divider the supply is given from the power supply and the ADC pin i use is B1 from the power supply when i give less than 2V the output in the live expression is accurate but when i give more than 2V and less than 3.3V it is not correct and for example if i give 3.3V in the live expression the output shows is 5.1345V how to resolve this problem any ideas gentlemen's 

This topic has been closed for replies.
Best answer by Peter BENSCH

This thread relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

Regards
/Peter

4 replies

Andrew Neil
Super User
September 16, 2024

Note that the chances of a Blue Pill containing a genuine STM32 are vanishingly small.

It's quite possible that a fake STM32 could have weird ADC behaviour.

The first thing to determine is whether the issue is just with the IDE and its live expression display, or in your code.

So what happens if you send your result out through a UART to a terminal?

If you see the same error doing that, then the problem is in your code.

 

Have you looked at the raw values from the ADC?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
September 16, 2024

Yes i have gone through the raw value of the ADC it correct

here is my program is there any correction

while (1)
  {
  HAL_ADC_PollForConversion(&hadc1,1000);
     readValue = HAL_ADC_GetValue(&hadc1);
     voltage =(float)readValue/4095*8.56;
     HAL_Delay(100);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
Karl Yamashita
Principal
September 16, 2024

Are you sure the 8.56 is the correct factor? What is your voltage divider R1 and R2? What is the max input voltage to the divider?

 

try 

voltage =(float)readValue * (3.3/4096) * 8.56; // assuming Vref = 3.3V

 

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Peter BENSCH
Peter BENSCHBest answer
Technical Moderator
April 25, 2025

This thread relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

Regards
/Peter