Skip to content

Commit e846c8c

Browse files
committed
[example] Add Nucleo-L552ZE-Q basic ADC example
1 parent ad071e4 commit e846c8c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2021, Raphael Lehmann
3+
* Copyright (c) 2022, Christopher Durand
4+
*
5+
* This file is part of the modm project.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
12+
#include <modm/board.hpp>
13+
14+
#undef MODM_LOG_LEVEL
15+
#define MODM_LOG_LEVEL modm::log::INFO
16+
17+
int
18+
main()
19+
{
20+
Board::initialize();
21+
22+
MODM_LOG_INFO << "STM32L5 ADC basic example" << modm::endl;
23+
MODM_LOG_INFO << " running on Nucleo-L552ZE-Q" << modm::endl << modm::endl;
24+
25+
MODM_LOG_INFO << "Configuring ADC ...";
26+
// max. ADC clock for STM32L552: 80 MHz
27+
// 110 MHz AHB clock / 2 = 55 MHz
28+
Adc1::initialize(
29+
Adc1::ClockMode::SynchronousPrescaler2,
30+
Adc1::ClockSource::SystemClock,
31+
Adc1::Prescaler::Disabled,
32+
Adc1::CalibrationMode::SingleEndedInputsMode,
33+
true);
34+
// GpioB1: A6
35+
Adc1::connect<GpioB1::In16>();
36+
Adc1::setPinChannel<GpioB1>(Adc1::SampleTime::Cycles13);
37+
38+
while (true)
39+
{
40+
Adc1::startConversion();
41+
while(!Adc1::isConversionFinished)
42+
;
43+
const auto adcValue = Adc1::getValue();
44+
MODM_LOG_INFO << "adcValue=" << adcValue;
45+
const float voltage = adcValue * 3.3 / 0xfff;
46+
MODM_LOG_INFO << " voltage=";
47+
MODM_LOG_INFO.printf("%.3f\n", voltage);
48+
Board::Leds::toggle();
49+
modm::delay(500ms);
50+
}
51+
52+
return 0;
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-l552ze-q</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_l552ze-q/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)