From 6ded6b1ebe6dfdbcebdec652df58d37b3f2932c4 Mon Sep 17 00:00:00 2001 From: Raphael Lehmann Date: Tue, 21 Dec 2021 07:44:27 +0100 Subject: [PATCH] [example] ADS816X ADC example for Nucleo-F429ZI --- examples/nucleo_f429zi/ads_ads816x/main.cpp | 68 +++++++++++++++++++ .../nucleo_f429zi/ads_ads816x/project.xml | 11 +++ 2 files changed, 79 insertions(+) create mode 100644 examples/nucleo_f429zi/ads_ads816x/main.cpp create mode 100644 examples/nucleo_f429zi/ads_ads816x/project.xml diff --git a/examples/nucleo_f429zi/ads_ads816x/main.cpp b/examples/nucleo_f429zi/ads_ads816x/main.cpp new file mode 100644 index 0000000000..44463c58e8 --- /dev/null +++ b/examples/nucleo_f429zi/ads_ads816x/main.cpp @@ -0,0 +1,68 @@ +/* + * 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 +#include +#include + +using namespace Board; + +using SpiMaster = SpiMaster1; +using Cs = GpioA4; +using Mosi = GpioB5; +using Miso = GpioB4; +using Sck = GpioB3; + +using Ads816x = modm::Ads816x; + +Ads816x adc{}; + +int +main() +{ + Board::initialize(); + Leds::setOutput(); + + MODM_LOG_INFO << "ADS816X Demo on Nucleo-F429ZI\n" << modm::endl; + + SpiMaster::initialize(); + SpiMaster::connect(); + + MODM_LOG_INFO << "ADC in manual mode:" << modm::endl; + RF_CALL_BLOCKING(adc.initialize(modm::ads816x::Mode::Manual)); + // Set channel 0 as next channel, ignore result + RF_CALL_BLOCKING(adc.manualModeConversion(0)); + + for (uint8_t i{1}; i <= 8; i++) { + uint16_t result = RF_CALL_BLOCKING(adc.manualModeConversion(i)); + MODM_LOG_INFO.printf("ADC Channel %u: %05u\n", (i-1), result); + } + + MODM_LOG_INFO << "\nADC in auto sequence mode:" << modm::endl; + RF_CALL_BLOCKING(adc.initialize(modm::ads816x::Mode::AutoSequence)); + + uint32_t counter(0); + + while (true) + { + Leds::write(counter % ((1 << (Leds::width+1)) - 1)); + + std::array results; + RF_CALL_BLOCKING(adc.autoSequenceConversion(0xff, results)); + MODM_LOG_INFO.printf("ADC Sequence: %05u %05u %05u %05u %05u %05u %05u %05u\n", + results[0], results[1], results[2], results[3], + results[4], results[5], results[6], results[7]); + + modm::delay(Button::read() ? 1ms : 1000ms); + } + + return 0; +} diff --git a/examples/nucleo_f429zi/ads_ads816x/project.xml b/examples/nucleo_f429zi/ads_ads816x/project.xml new file mode 100644 index 0000000000..624827aad4 --- /dev/null +++ b/examples/nucleo_f429zi/ads_ads816x/project.xml @@ -0,0 +1,11 @@ + + modm:nucleo-f429zi + + + + + modm:build:scons + modm:platform:spi:1 + modm:driver:ads816x + +