diff --git a/examples/nucleo_f042k6/adc/main.cpp b/examples/nucleo_f042k6/adc/main.cpp index 5938535ac9..a351d0bb17 100644 --- a/examples/nucleo_f042k6/adc/main.cpp +++ b/examples/nucleo_f042k6/adc/main.cpp @@ -23,17 +23,30 @@ main() LedD13::setOutput(); Adc::connect(); - Adc::initialize(Adc::ClockMode::PCLKDividedBy4, Adc::CalibrationMode::DoNotCalibrate); + Adc::initialize(); + + uint16_t Vref = Adc::readInternalVoltageReference(); + int16_t Temp = Adc::readTemperature(Vref); + MODM_LOG_INFO << "Vref=" << Vref << modm::endl; + MODM_LOG_INFO << "Temp=" << Temp << modm::endl; + + MODM_LOG_INFO << "TS_CAL1=" << uint16_t(*((volatile uint16_t *)0x1FFF77B8)) << modm::endl; + MODM_LOG_INFO << "TS_CAL2=" << uint16_t(*((volatile uint16_t *)0x1FFF77C2)) << modm::endl; + MODM_LOG_INFO << "VREFINT_CAL=" << uint16_t(*((volatile uint16_t *)0x1FFFF7BA)) << modm::endl; + + Adc::setPinChannel(); + Adc::setResolution(Adc::Resolution::Bits12); + Adc::setRightAdjustResult(); + Adc::setSampleTime(Adc::SampleTime::Cycles239_5); + Adc::enableFreeRunningMode(); + Adc::startConversion(); while (true) { LedD13::toggle(); - modm::delayMilliseconds(250); + modm::delayMilliseconds(100); - Adc::setPinChannel(); - Adc::startConversion(); - while(!Adc::isConversionFinished()) { } - MODM_LOG_INFO << "ADC A0: " << Adc::getValue() << modm::endl; + MODM_LOG_INFO << "mV=" << (Vref * Adc::getValue() / 4095ul) << modm::endl; } diff --git a/examples/nucleo_g071rb/adc/main.cpp b/examples/nucleo_g071rb/adc/main.cpp new file mode 100644 index 0000000000..4747e5c97a --- /dev/null +++ b/examples/nucleo_g071rb/adc/main.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019, Niklas Hauser + * + * 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 + +using namespace Board; + +// ---------------------------------------------------------------------------- +int +main() +{ + Board::initialize(); + LedD13::setOutput(); + Adc1::connect(); + + Adc1::initialize(); + + uint16_t Vref = Adc1::readInternalVoltageReference(); + int16_t Temp = Adc1::readTemperature(Vref); + MODM_LOG_INFO << "Vref=" << Vref << modm::endl; + MODM_LOG_INFO << "Temp=" << Temp << modm::endl; + + MODM_LOG_INFO << "TS_CAL1=" << uint16_t(*((volatile uint16_t *)0x1FFF75A8)) << modm::endl; + MODM_LOG_INFO << "TS_CAL2=" << uint16_t(*((volatile uint16_t *)0x1FFF75CA)) << modm::endl; + MODM_LOG_INFO << "VREFINT_CAL=" << uint16_t(*((volatile uint16_t *)0x1FFF75AA)) << modm::endl; + MODM_LOG_INFO << "ADC_CALFACT=" << uint16_t(ADC1->CALFACT) << modm::endl; + + Adc1::setPinChannel(); + Adc1::setResolution(Adc1::Resolution::Bits12); + Adc1::setRightAdjustResult(); + Adc1::setSampleTime(Adc1::SampleTime::Cycles160_5); + Adc1::enableFreeRunningMode(); + Adc1::enableOversampling(Adc1::OversampleRatio::x256, Adc1::OversampleShift::Div256); + Adc1::startConversion(); + + while (true) + { + LedD13::toggle(); + modm::delayMilliseconds(100); + + MODM_LOG_INFO << "mV=" << (Vref * Adc1::getValue() / 4095ul) << modm::endl; + } + + return 0; +} diff --git a/examples/nucleo_g071rb/adc/project.xml b/examples/nucleo_g071rb/adc/project.xml new file mode 100644 index 0000000000..d28f13fab2 --- /dev/null +++ b/examples/nucleo_g071rb/adc/project.xml @@ -0,0 +1,11 @@ + + modm:nucleo-g071rb + + + + + modm:platform:gpio + modm:platform:adc + modm:build:scons + + diff --git a/src/modm/board/nucleo_g071rb/board.hpp b/src/modm/board/nucleo_g071rb/board.hpp index 6075dad7c8..09459fbb33 100644 --- a/src/modm/board/nucleo_g071rb/board.hpp +++ b/src/modm/board/nucleo_g071rb/board.hpp @@ -48,7 +48,7 @@ struct SystemClock { static constexpr uint32_t Spi1 = Apb; static constexpr uint32_t I2s1 = Apb; static constexpr uint32_t Timer1 = Apb; - static constexpr uint32_t Adc = Apb; + static constexpr uint32_t Adc1 = Apb; static constexpr uint32_t Comp = Apb; static constexpr uint32_t ItLine = Apb; static constexpr uint32_t VrefBuf = Apb;