cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE Voltage Sensor with STM32F103C8T6

i_am_sandy
Associate II

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 discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

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

In order 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.

View solution in original post

4 REPLIES 4

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.
i_am_sandy
Associate II

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

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

 

 

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.
Peter BENSCH
ST Employee

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

In order 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.