Skip to content

Commit

Permalink
[example] ADIS16470 IMU example for Nucleo-F429ZI
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Jan 5, 2022
1 parent 688f9a4 commit 216548d
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
93 changes: 93 additions & 0 deletions examples/nucleo_f429zi/imu_adis16470/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <modm/board.hpp>
#include <modm/platform/spi/spi_master_1.hpp>
#include <modm/driver/inertial/adis16470.hpp>

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<SpiMaster, Cs>;

Adis16470 imu{};

int
main()
{
Board::initialize();
Leds::setOutput();

MODM_LOG_INFO << "ADIS16470 IMU demo on Nucleo-F429ZI\n" << modm::endl;

SpiMaster::initialize<Board::SystemClock, 1.3_MHz>();
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();

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<uint16_t, 11> 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<int16_t>(data[2]));
MODM_LOG_INFO.printf("Y_GYRO_OUT=%+05i, ", static_cast<int16_t>(data[3]));
MODM_LOG_INFO.printf("Z_GYRO_OUT=%+05i, ", static_cast<int16_t>(data[4]));
MODM_LOG_INFO.printf("X_ACCL_OUT=%+05i, ", static_cast<int16_t>(data[5]));
MODM_LOG_INFO.printf("Y_ACCL_OUT=%+05i, ", static_cast<int16_t>(data[6]));
MODM_LOG_INFO.printf("Z_ACCL_OUT=%+05i, ", static_cast<int16_t>(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;
}
11 changes: 11 additions & 0 deletions examples/nucleo_f429zi/imu_adis16470/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-f429zi</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f429zi/imu_adis16470</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:spi:1</module>
<module>modm:driver:adis16470</module>
</modules>
</library>

0 comments on commit 216548d

Please sign in to comment.