From c1a2d5a307702a7cff671b251309f6f3b34c9087 Mon Sep 17 00:00:00 2001 From: Raphael Lehmann Date: Mon, 3 Jan 2022 09:47:36 +0100 Subject: [PATCH] [example] ADIS16470 IMU example for Nucleo-F429ZI --- examples/nucleo_f429zi/imu_adis16470/main.cpp | 93 +++++++++++++++++++ .../nucleo_f429zi/imu_adis16470/project.xml | 11 +++ 2 files changed, 104 insertions(+) create mode 100644 examples/nucleo_f429zi/imu_adis16470/main.cpp create mode 100644 examples/nucleo_f429zi/imu_adis16470/project.xml diff --git a/examples/nucleo_f429zi/imu_adis16470/main.cpp b/examples/nucleo_f429zi/imu_adis16470/main.cpp new file mode 100644 index 0000000000..628a588ccb --- /dev/null +++ b/examples/nucleo_f429zi/imu_adis16470/main.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022, 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 Mosi = GpioB5; +using Miso = GpioB4; +using Sck = GpioB3; +using Cs = GpioA4; +using Dr = GpioF12; +using Rst = GpioUnused; + +using Adis16470 = modm::Adis16470; + +Adis16470 imu{}; + +int +main() +{ + Board::initialize(); + Leds::setOutput(); + + MODM_LOG_INFO << "ADIS16470 IMU demo on Nucleo-F429ZI\n" << modm::endl; + + SpiMaster::initialize(); + SpiMaster::connect(); + + Rst::setOutput(); + Dr::setInput(); + + // Reset ADS816x chip + Rst::reset(); + modm::delay(10ms); + Rst::set(); + + // Wait start-up time + modm::delay(252ms); + + MODM_LOG_INFO << "Initializing IMU..." << modm::endl; + RF_CALL_BLOCKING(imu.initialize()); + + // Configure IMU ... + imu.writeRegister(modm::adis16470::Register::FILT_CTRL, 0); + // ... + + uint32_t counter(0); + + std::array data; + + while (true) + { + Leds::write(counter % ((1 << (Leds::width+1)) - 1)); + + MODM_LOG_INFO.printf("\nIMU data: "); + + while( !Dr::read() ) { + // wait... + modm::delay(1us); + } + if( !RF_CALL_BLOCKING(imu.readRegisterBurst(data))) { + MODM_LOG_INFO.printf("checksum mismatch!\n\n"); + } + else { + MODM_LOG_INFO.printf("DIAG_STAT=%05u, ", data[1]); + MODM_LOG_INFO.printf("X_GYRO_OUT=%+05i, ", static_cast(data[2])); + MODM_LOG_INFO.printf("Y_GYRO_OUT=%+05i, ", static_cast(data[3])); + MODM_LOG_INFO.printf("Z_GYRO_OUT=%+05i, ", static_cast(data[4])); + MODM_LOG_INFO.printf("X_ACCL_OUT=%+05i, ", static_cast(data[5])); + MODM_LOG_INFO.printf("Y_ACCL_OUT=%+05i, ", static_cast(data[6])); + MODM_LOG_INFO.printf("Z_ACCL_OUT=%+05i, ", static_cast(data[7])); + MODM_LOG_INFO.printf("TEMP_OUT=%+05i (1/10 °C), ", data[8]); + MODM_LOG_INFO.printf("DATA_CNTR=%05u, ", data[9]); + MODM_LOG_INFO.printf("checksum=%05u\n", data[10]); + } + + modm::delay(750us); + } + + return 0; +} diff --git a/examples/nucleo_f429zi/imu_adis16470/project.xml b/examples/nucleo_f429zi/imu_adis16470/project.xml new file mode 100644 index 0000000000..5692204e28 --- /dev/null +++ b/examples/nucleo_f429zi/imu_adis16470/project.xml @@ -0,0 +1,11 @@ + + modm:nucleo-f429zi + + + + + modm:build:scons + modm:platform:spi:1 + modm:driver:adis16470 + +