The purpose of this experiment is to create a volt meter, where we will use an RT-Thread RT-Spark development board (STM32F407ZGT6) to measure how the CR2032 coin cell battery discharges.
Phase 1: STM32CubeMX Configuration1.New Project: Open your STM32CubeMX and select the STM32F407ZGT6 as your target microcontroller.
2.Enable the ADC: Navigate to Analog then ADC1.
- Check the box for IN2 (which corresponds to the PA2 pin you wired up).
- Under ADC_Settings, set ClockPrescaler to PCLK2 divided by 8.
- Ensure the Resolution is set to 12 bits (15 ADC Clock cycles)
3.Project Manager Settings:
- Name your project in Project Manager tab.
- Under Toolchain/IDE, select STM32CubeIDE.
- Check the option to "Generate peripheral initialization as a pair of '.c/.h' files per peripheral".
- Click Generate Code and then open the project in your standalone STM32CubeIDE application.
- Connect a jumper wire from the positive (+) side of your external battery to the top leg of your R1 resistor on the breadboard (your "Battery/Source Voltage +" row).
- Connect a jumper wire from the negative (-) side of your external battery to the Ground rail on your breadboard.
- Keep the black jumper wire that connects the breadboard's ground to the RT-Spark's ground pin.
- Connect the jumper wire in the middle of the two resistor to PA2 pin of RT-Spark.
- Open
Core/Src/main.c. Scroll down to theUSER CODE BEGIN PVsection and add your variables.
- Scroll down to your
main()function. Inside the infinitewhile (1)loop, place your logic in theUSER CODE BEGIN 3section.
- Compile and Launch: Click the Build (hammer) icon to compile. Once you see "0 errors", click the Debug (bug) icon to flash the code to the RT-Spark board.
- Set Up the Tracker: When the debugger pauses at the start of
main(), switch from the "Variables" tab to the Live Expressions tab. AddrawValueandvoltage. - Run Real-Time: Click the Resume (Play) button in the top toolbar (or press F8).
- Observe and Record: * The
0values will instantly update to reflect the actual voltage passing through the breadboard.






Comments