From 6c4bccf293a0918ec0da14e1777ba84eba08fadf Mon Sep 17 00:00:00 2001 From: mokhwasomssi Date: Wed, 25 Aug 2021 11:09:48 +0900 Subject: [PATCH] Update README.md - add example code --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9f2b864..4bde7e1 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,65 @@ __TAG - `ICM-20948` `AK09916` `SPI` `STM32 HAL`__ - STM32CubeIDE - STM32 HAL driver - STM32F411CEU6 +- ICM-20948 module ( [SparkFun 9Dof IMU Breakout - ICM-20948 (Qwiic)](https://www.sparkfun.com/products/15335) ) -## ICM-20948 module -[SparkFun 9Dof IMU Breakout - ICM-20948 (Qwiic)](https://www.sparkfun.com/products/15335) - - + + ## STM32CubeMX -### SPI +![image](https://user-images.githubusercontent.com/48342925/130714344-753f1b21-abe7-412c-b723-0826e43b9203.png) + +### SPI ![image](https://user-images.githubusercontent.com/48342925/129033034-ef4d8818-7338-4d90-bcd9-9d66491074bd.png) #### GPIO - ![image](https://user-images.githubusercontent.com/48342925/129033151-7cf98ef2-22e9-44ef-8ddd-77b6ea9abf0b.png) + + +## Example + +### icm20948.h +- SPI1, PA4 (CS Pin) + +```c +/* 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 + +```c +#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); + } +} +``` \ No newline at end of file