diff --git a/examples/nucleo_f042k6/tmp12x/main.cpp b/examples/nucleo_f042k6/tmp12x/main.cpp new file mode 100644 index 0000000000..3be43dbfa6 --- /dev/null +++ b/examples/nucleo_f042k6/tmp12x/main.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021, 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 +#include +#include + +using namespace Board; +using namespace std::chrono_literals; + +/* + * Example for the TMP12x driver + * It assumes a TMP121 or TM123 is connected to the following pins: + * A4 CS + * A5 SCK + * A6 MISO + */ + +using SpiCs = GpioA4; +using SpiSck = GpioA5; +using SpiMiso = GpioA6; + +int +main() +{ + Board::initialize(); + + MODM_LOG_INFO << "TMP12x test" << modm::endl; + + SpiMaster1::connect(); + SpiMaster1::initialize(); + + modm::Tmp123 sensor; + sensor.initialize(); + + modm::PeriodicTimer timer{500ms}; + while(true) { + if (timer.execute()) { + const modm::Tmp123Temperature temperature = RF_CALL_BLOCKING(sensor.read()); + MODM_LOG_INFO.printf("Temperature %2.2f\n", temperature.getTemperatureFloat()); + } + } +} diff --git a/examples/nucleo_f042k6/tmp12x/project.xml b/examples/nucleo_f042k6/tmp12x/project.xml new file mode 100644 index 0000000000..040aca166d --- /dev/null +++ b/examples/nucleo_f042k6/tmp12x/project.xml @@ -0,0 +1,12 @@ + + modm:nucleo-f042k6 + + + + + modm:build:scons + modm:driver:tmp12x + modm:platform:spi:1 + modm:processing:timer + +