# ICM 20948 driver for STM32 Basic driver for TDK InvenSense ICM-20948. It support 2 modes: - pooling - interrupt # working modes ## Pooling ```c #include "icm20948.h" Device_TypeDef *module; void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == ICM_INT_Pin){ module->Read(); } } int main(void) { // HAL_Init, etc... axises *my_gyro2 = NULL; axises *my_accel2 = NULL; module = &icmModule; McuPin_typeDef pinCS; // CS for SPI McuPin_typeDef pinINT; // INT pin from ICM pinCS.port = SPI2_CS_GPIO_Port; pinCS.pin = SPI2_CS_Pin; // initialization of module module->Init(&hspi2, &pinCS, NULL); while (1) { // read raw values module->acc->Read(&my_accel); module->gyro->Read(my_gyro2); module->mag->Read(&my_mag); // or unit conversion module->acc->ReadUnit(&my_accel); module->gyro->ReadUnit(&my_gyro); module->mag->ReadUnit(&my_mag); HAL_Delay(10); // waint 10 ms } } ``` ## Interrupt ```c #include "icm20948.h" Device_TypeDef *module; volatile uint8_t icm_ready; void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == ICM_INT_Pin){ icm_ready = 1; } } int main(void) { // HAL_Init, etc... axises *my_gyro2 = NULL; axises *my_accel2 = NULL; module = &icmModule; McuPin_typeDef pinCS; // CS for SPI McuPin_typeDef pinINT; // INT pin from ICM pinCS.port = SPI2_CS_GPIO_Port; pinCS.pin = SPI2_CS_Pin; pinINT.port = ICM_INT_GPIO_Port; pinINT.pin = ICM_INT_Pin; // initialization of module module->Init(&hspi2, &pinCS, &pinINT); while (1) { if(icm_ready == 1){ module->Read(); icm_ready = 0; my_accel2 = module->acc->GetData(); my_gyro2 = module->gyro->GetData(); // .... } } } ```