-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Add Nucleo-L552ZE-Q basic ADC example
- Loading branch information
1 parent
ad071e4
commit e846c8c
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2021, Raphael Lehmann | ||
* Copyright (c) 2022, Christopher Durand | ||
* | ||
* 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 << "STM32L5 ADC basic example" << modm::endl; | ||
MODM_LOG_INFO << " running on Nucleo-L552ZE-Q" << modm::endl << modm::endl; | ||
|
||
MODM_LOG_INFO << "Configuring ADC ..."; | ||
// max. ADC clock for STM32L552: 80 MHz | ||
// 110 MHz AHB clock / 2 = 55 MHz | ||
Adc1::initialize( | ||
Adc1::ClockMode::SynchronousPrescaler2, | ||
Adc1::ClockSource::SystemClock, | ||
Adc1::Prescaler::Disabled, | ||
Adc1::CalibrationMode::SingleEndedInputsMode, | ||
true); | ||
// GpioB1: A6 | ||
Adc1::connect<GpioB1::In16>(); | ||
Adc1::setPinChannel<GpioB1>(Adc1::SampleTime::Cycles13); | ||
|
||
while (true) | ||
{ | ||
Adc1::startConversion(); | ||
while(!Adc1::isConversionFinished) | ||
; | ||
const auto adcValue = Adc1::getValue(); | ||
MODM_LOG_INFO << "adcValue=" << adcValue; | ||
const float voltage = adcValue * 3.3 / 0xfff; | ||
MODM_LOG_INFO << " voltage="; | ||
MODM_LOG_INFO.printf("%.3f\n", voltage); | ||
Board::Leds::toggle(); | ||
modm::delay(500ms); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-l552ze-q</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_l552ze-q/adc_basic</option> | ||
</options> | ||
<modules> | ||
<module>modm:debug</module> | ||
<module>modm:platform:adc:1</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |