/stm32_hal_icm20948

ICM-20948 library with STM32 HAL driver

Primary LanguageC

stm32_hal_icm20948

Brief

ICM-20948 is 9-axis IMU sensor.
TAG - ICM-20948 AK09916 SPI STM32 HAL

Axis Not Recommended for New Designs Recommended for New Designs
6-axis MPU-6050 ICM-20602
9-axis MPU-9250 ICM-20948

Library Feature

  • Read sensor data
  • Offset cancellation

Dev Environment

STM32CubeMX

image

SPI

image

GPIO

image

Example

icm20948.h

  • SPI1, PA4 (CS Pin)
/* User Configuration */
#define ICM20948_SPI					(&hspi1)

#define ICM20948_SPI_CS_PIN_PORT		GPIOA
#define ICM20948_SPI_CS_PIN_NUMBER		GPIO_PIN_4

main.c

  • only contain relative things
#include "icm20948.h"

// variables to store sensor data
axises my_gyro;
axises my_accel;
axises my_mag;

int main(void)
{
    // initialize
    // Modify the inside of init function for personal setting.
    icm20948_init();
    ak09916_init();

    while (1)
    {
        // raw data
        icm20948_gyro_read(&my_gyro);
        icm20948_accel_read(&my_accel);
        ak09916_mag_read(&my_mag);

        // or unit conversion
        icm20948_gyro_read_dps(&my_gyro);
        icm20948_accel_read_g(&my_accel);
        ak09916_mag_read_uT(&my_mag);
    }
}