Skip to content

Commit 22275c0

Browse files
committed
[examples] Nucleo_G474RE: Add basic ADC example
1 parent 86b9664 commit 22275c0

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2021, Raphael Lehmann
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <modm/board.hpp>
12+
13+
#undef MODM_LOG_LEVEL
14+
#define MODM_LOG_LEVEL modm::log::INFO
15+
16+
int
17+
main()
18+
{
19+
Board::initialize();
20+
21+
MODM_LOG_INFO << "STM32G4 ADC basic example" << modm::endl;
22+
MODM_LOG_INFO << " running on Nucleo-G474RE" << modm::endl << modm::endl;
23+
24+
MODM_LOG_INFO << "Configuring ADC ...";
25+
Adc1::initialize(
26+
Adc1::ClockMode::SynchronousPrescaler1,
27+
Adc1::ClockSource::SystemClock,
28+
Adc1::Prescaler::Disabled,
29+
Adc1::CalibrationMode::SingleEndedInputsMode,
30+
true);
31+
Adc1::connect<GpioA0::In1>();
32+
Adc1::setPinChannel<GpioA0>(Adc1::SampleTime::Cycles13);
33+
34+
while (true)
35+
{
36+
Adc1::startConversion();
37+
while(!Adc1::isConversionFinished)
38+
;
39+
int adcValue = Adc1::getValue();
40+
MODM_LOG_INFO << "adcValue=" << adcValue;
41+
float voltage = adcValue * 3.3 / 0xfff;
42+
MODM_LOG_INFO << " voltage=";
43+
MODM_LOG_INFO.printf("%.3f\n", voltage);
44+
modm::delay(500ms);
45+
}
46+
47+
return 0;
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-g474re</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_g474re/adc_basic</option>
5+
</options>
6+
<modules>
7+
<module>modm:debug</module>
8+
<module>modm:platform:adc:1</module>
9+
<module>modm:build:scons</module>
10+
</modules>
11+
</library>

0 commit comments

Comments
 (0)