-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (43 loc) · 1.25 KB
/
main.cpp
File metadata and controls
50 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2021, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <modm/board.hpp>
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO
int
main()
{
Board::initialize();
MODM_LOG_INFO << "STM32G4 ADC basic example" << modm::endl;
MODM_LOG_INFO << " running on Nucleo-G474RE" << modm::endl << modm::endl;
MODM_LOG_INFO << "Configuring ADC ...";
// max. ADC clock for STM32G474: 60 MHz
// 170 MHz AHB clock / 4 = 42.5 MHz
Adc1::initialize(
Adc1::ClockMode::SynchronousPrescaler4,
Adc1::ClockSource::SystemClock,
Adc1::Prescaler::Disabled,
Adc1::CalibrationMode::SingleEndedInputsMode,
true);
Adc1::connect<GpioA0::In1>();
Adc1::setPinChannel<GpioA0>(Adc1::SampleTime::Cycles13);
while (true)
{
Adc1::startConversion();
while(!Adc1::isConversionFinished())
;
int adcValue = Adc1::getValue();
MODM_LOG_INFO << "adcValue=" << adcValue;
float voltage = adcValue * 3.3 / 0xfff;
MODM_LOG_INFO << " voltage=";
MODM_LOG_INFO.printf("%.3f\n", (double)voltage);
modm::delay(500ms);
}
return 0;
}