Skip to content

Commit

Permalink
[example] Add Nucleo-L552ZE-Q basic ADC example
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Jan 19, 2022
1 parent ad071e4 commit e846c8c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/nucleo_l552ze-q/adc_basic/main.cpp
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;
}
11 changes: 11 additions & 0 deletions examples/nucleo_l552ze-q/adc_basic/project.xml
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>

0 comments on commit e846c8c

Please sign in to comment.