0
\$\begingroup\$

So I've just migrated to STM32 Black Pill from my Arduino UNO. I've simply copied the Arduino code into the Black Pill using this method. On my arduino I was using a pressure sensor powered with 5V and reference pin to 3.3V. In the Black Pill I've done the same and connected the 5V and the 3.3V to those same wires going to the sensor. I've connected the signal output wire to A0 in the Black Pill to read the analogue signal. I have the following issues...

  1. Unlike the Arduino, I am not getting a linear output here. Tested against a manometer, for equal level of pressure rise I am not getting equal ADC reading change.

  2. The ADC values start at 318 and end at 330. I am unable to rise beyond 330.

I would like to know the reasons for these issues and their solution

I would like to know how many ADC divisions does this board have and how many volts can it measure.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Surely those parameters can be found in the datasheet. However your problem is likely to be in hardware or software and you provide almost no info to solve it. \$\endgroup\$
    – Justme
    Commented Aug 24, 2022 at 11:53

3 Answers 3

1
\$\begingroup\$

The Black Pill uses a STM32F411CE if I'm not mistaken.

It's a good thing to start reading the reference manual and datasheet. Yes it can be confusing and yes it's a skill you should absolutely learn if you want to get further down the road of EE. The chapter overview is your friend to find things more easily.

The reference manual will tell you: it's a 12 bit ADC, but it has a configurable resolution, so it can be 6, 8, 10 or 12 bit.

No idea how you have configured it (or the Arduino thing does it).

It also tells you, that the positive reference voltage is whatever is supplied to the Vref+ pin. I'd guess that it is connected to 3.3 V, but that is only a guess. And you can't read more than that.

In default settings a value of 318 would correspond to 256 mV and 330 to 265 mV. I'd check with a multimeter what the value really is.

\$\endgroup\$
1
\$\begingroup\$

The STM32F401CCU6 has a single 12-bit ADC and in the "Black Pill", the reference is generally tied to the 3.3V supply rail via a ferrite bead (with a bypass capacitor, though that's not shown on some schematics).

The symptoms suggest a pin or ADC configuration issue, which would be down to the Arduino environment and possibly your choice of the ADC input pin. The Arduino SE may be a better place to ask.

To figure things out yourself (or to ask someone to help) you should find the following documents:

  • Your connection schematic
  • Black pill schematic
  • STM32F401CCU6 datasheet
  • STM32f401CCU6 reference manual
  • HAL documentation (the Arduino IDE uses HAL functions)

.. and you may need to dig into the SOURCE code. Since the Arduino IDE does not provide the source code you'll need to download that separately. For example, files such as PeripheralPins_BLACKPILL_F401CC.c are a must if the default configuration is unacceptable- you can override "weak" declarations in your code without actually modifying the pre-compiled parts.

If you want to continue to work in the dark, simply try another ADC input pin and see if that works.

\$\endgroup\$
0
\$\begingroup\$

Just a rough guide: Use Cube IDE, select your processor, create a project. Under SYS, set your debugger, if neccessary. Under Analog, set the ADC settings as needed. Generate the code. Notice the genrated MX_ADC_Init function. Notice the file drivers/STM32.../inc/stm32..._adc.h There you have your API. Specificcaly HAL_ADC_Start HAL_ADC_Start_IT HAL_ADC_Start_DMA and then HAL_ADC_GetValue

You can find a CubeMX package for your controller family and check any of the ADC examples. like here https://github.com/STMicroelectronics/STM32CubeF1

If you have an F1. If ists L1 or F3 or another, just use the proper Cube package. Clone it, import the project into CubeIde from sometinng like here: (your git repo base dir)\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples\ADC\ADC_AnalogWatchdog\EWARM Use "Import ac6 System Workbench for STM32 Project" to convert it for CubeIde."

I know Eclipse CDT is terrible, if you have something better let me know ;)

\$\endgroup\$
2
  • \$\begingroup\$ Not exactly sure why CDT qualifies as terrible, you could try VS Code. It's a bit harder to setup, but after that it works quite nicely. \$\endgroup\$
    – Arsenal
    Commented Aug 24, 2022 at 14:49
  • \$\begingroup\$ No offence, it's just a personal opinion. Some very basic things are just overcomplicated or not workable. But since it's free, I have no right to complain. \$\endgroup\$ Commented Dec 25, 2022 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.