From 6e701f3ae8e4263a4d89a531acaa4913c22f73b6 Mon Sep 17 00:00:00 2001 From: lijie Date: Fri, 8 Mar 2024 16:50:42 +0800 Subject: [PATCH] =?UTF-8?q?ICM428688=E7=A1=AC=E4=BB=B6spi=E9=80=9A?= =?UTF-8?q?=E8=AE=AF=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/mymain.c | 5 +- IMU/icm42688.c | 1126 ++++++++++++++++++++++++------------------------ IMU/icm42688.h | 508 +++++++++++----------- 3 files changed, 817 insertions(+), 822 deletions(-) diff --git a/APP/mymain.c b/APP/mymain.c index 583adee..1864eab 100644 --- a/APP/mymain.c +++ b/APP/mymain.c @@ -11,8 +11,8 @@ void mymain() led_init(); adc_init(); tle5012b_init(); -// Init_ICM42688(); -// imu_rest(); + Init_ICM42688(); + imu_rest(); moto_Init(); PID_Iint(); setvbuf(stdout, NULL, _IONBF, 0); //½â¾öprintfûÓÐ\n²»·¢ËÍÎÊÌâ @@ -51,7 +51,6 @@ void mymain() // printf("%d\n",i); // } // i++; -// // Data_send(x,y); // HAL_Delay(3); } diff --git a/IMU/icm42688.c b/IMU/icm42688.c index 33fa8c0..cce01b8 100644 --- a/IMU/icm42688.c +++ b/IMU/icm42688.c @@ -1,306 +1,51 @@ -//#include "icm42688.h" -// -//#include "kalman.h" -//#include "alldata.h" -// -//static float icm42688_acc_inv = 1, icm42688_gyro_inv = 1; -// -//void Spi_GPIO_Init() -//{ -// GPIO_InitTypeDef GPIO_InitStruct = {0}; -// __HAL_RCC_GPIOB_CLK_ENABLE(); -// /*Configure GPIO pins : PBPin PB12 */ -// GPIO_InitStruct.Pin = GPIO_PIN_12; -// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; -// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -//} -// -//void Init_ICM42688(void) -//{ -// printf("Init_ICM42688\r\n"); -// HAL_Delay(1000); -// HAL_Delay(1000); -// unsigned char model; -// Spi_GPIO_Init(); -// // ¶ÁÈ¡ÍÓÂÝÒÇÐͺÅÍÓÂÝÒÇ×Ô¼ì -// model = 0xff; -// while(1) -// { -// Read_Datas_ICM42688(ICM42688_WHO_AM_I, &model, 1); -// if(model == 0x47) -// { -// printf("model:%x\r\n",model); -// HAL_Delay(1000); -// HAL_Delay(1000); -// break; -// } -// ICM42688_DELAY_MS(100); -// } -// Write_Data_ICM42688(ICM42688_PWR_MGMT0,0x00); // ¸´Î»É豸 -// ICM42688_DELAY_MS(10); // ²Ù×÷ÍêPWR¡ªMGMT0¼Ä´æÆ÷ºó200usÄÚ²»ÄÜÓÐÈκζÁд¼Ä´æÆ÷µÄ²Ù×÷ -// // ÉèÖÃICM42688¼ÓËٶȼƺÍÍÓÂÝÒǵÄÁ¿³ÌºÍÊä³öËÙÂÊ -// Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G, ICM42688_AODR_32000HZ, ICM42688_GFS_2000DPS, ICM42688_GODR_32000HZ); -// Write_Data_ICM42688(ICM42688_PWR_MGMT0, 0x0f); // ÉèÖÃGYRO_MODE,ACCEL_MODEΪµÍÔëÉùģʽ -// ICM42688_DELAY_MS(10); -//} -// -//void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr) -//{ -// Write_Data_ICM42688(ICM42688_ACCEL_CONFIG0, (afs << 5) | (aodr + 1)); // ³õʼ»¯ACCELÁ¿³ÌºÍÊä³öËÙÂÊ(p77) -// Write_Data_ICM42688(ICM42688_GYRO_CONFIG0, (gfs << 5) | (godr + 1)); // ³õʼ»¯GYROÁ¿³ÌºÍÊä³öËÙÂÊ(p76) -// -// switch(afs) -// { -// case ICM42688_AFS_2G: -// icm42688_acc_inv = 2000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À2g -// break; -// case ICM42688_AFS_4G: -// icm42688_acc_inv = 4000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À4g -// break; -// case ICM42688_AFS_8G: -// icm42688_acc_inv = 8000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À8g -// break; -// case ICM42688_AFS_16G: -// icm42688_acc_inv = 16000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À16g -// break; -// default: -// icm42688_acc_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý -// break; -// } -// switch(gfs) -// { -// case ICM42688_GFS_15_625DPS: -// icm42688_gyro_inv = 15.625f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À15.625dps -// break; -// case ICM42688_GFS_31_25DPS: -// icm42688_gyro_inv = 31.25f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À31.25dps -// break; -// case ICM42688_GFS_62_5DPS: -// icm42688_gyro_inv = 62.5f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À62.5dps -// break; -// case ICM42688_GFS_125DPS: -// icm42688_gyro_inv = 125.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À125dps -// break; -// case ICM42688_GFS_250DPS: -// icm42688_gyro_inv = 250.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À250dps -// break; -// case ICM42688_GFS_500DPS: -// icm42688_gyro_inv = 500.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À500dps -// break; -// case ICM42688_GFS_1000DPS: -// icm42688_gyro_inv = 1000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À1000dps -// break; -// case ICM42688_GFS_2000DPS: -// icm42688_gyro_inv = 2000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À2000dps -// break; -// default: -// icm42688_gyro_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý -// break; -// } -//} -// -///** -//* -//* @brief ICM42688ÍÓÂÝÒÇдÊý¾Ý -//* @param reg ¼Ä´æÆ÷ -//* @param data ÐèҪд½ø¸Ã¼Ä´æÆ÷µÄÊý¾Ý -//* @return void -//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ -//* Example: Write_Data_ICM42688(0x00,0x00); -//* -//**/ -//static void Write_Data_ICM42688(unsigned char reg, unsigned char dat) -//{ -// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,0); -// HAL_SPI_Transmit(&hspi2, ®, 1, 0xff); -// HAL_SPI_Transmit(&hspi2, &dat, 1, 0xff); -// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,1); -//} -// -///** -//* -//* @brief ICM42688ÍÓÂÝÒǶÁÊý¾Ý -//* @param reg ¼Ä´æÆ÷ -//* @param data °Ñ¶Á³öµÄÊý¾Ý´æÈëdata -//* @param num Êý¾Ý¸öÊý -//* @return void -//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ -//* Example: Read_Datas_ICM42688(0x00,0x00,1); -//* -//**/ -//static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num) -//{ -// uint8_t Data; -// reg |= 0x80; -// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,0); -// HAL_SPI_Transmit(&hspi2, ®, 1, 0xff ); -// while(num--) -// { -// HAL_SPI_Receive(&hspi2,&Data, 1, 0xff); -// *dat = Data; -// dat++; -// } -// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,1); -//} -///* ¶ÁÈ¡MPU6050Êý¾Ý²¢¼ÓÂ˲¨ */ -////·µ»ØÖµ:0,Õý³£ -////ÆäËû,´íÎó´úÂë -//_st_Mpu ICM42688; -//static volatile int16_t *pMpu = (int16_t *)&ICM42688; -//int16_t MpuOffset[6] = {0}; //MPU6050²¹³¥ÊýÖµ -// -//uint8_t MpuGetData(void) -//{ -// uint8_t i; -// uint8_t buffer[12]; -// Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1,buffer,12); -// -// for(i=0;i<6;i++) -// { -// pMpu[i] = (((int16_t)buffer[i<<1] << 8) | buffer[(i<<1)+1])-MpuOffset[i]; /* ½«Êý¾ÝÕûΪ16bit£¬²¢¼õȥˮƽУ׼ֵ */ -// if(i < 3) /* ½Ç¼ÓËÙ¶È¿¨¶ûÂüÂ˲¨ */ -// { -// { -// static struct KalmanFilter EKF[3] = {{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543}}; -// kalmanfiter(&EKF[i],(float)pMpu[i]); -// pMpu[i] = (int16_t)EKF[i].Out; -// } -// } -// if(i > 2) /* ½ÇËÙ¶ÈÒ»½×»¥²¹Â˲¨ */ -// { -// uint8_t k=i-3; -// const float factor = 0.15f; -// static float tBuff[3]; -// -// pMpu[i] = tBuff[k] = tBuff[k] * (1 - factor) + pMpu[i] * factor; -// } -// } -// return 0; -//} - - - - - - - - - - - - - - - -///////////Ä£Äâspi°æ±¾ #include "icm42688.h" #include "kalman.h" #include "alldata.h" -// ICM42688¼ÓËٶȼÆÊý¾Ý -float icm42688_acc_x, icm42688_acc_y, icm42688_acc_z ; -// ICM42688½Ç¼ÓËÙ¶ÈÊý¾Ý -float icm42688_gyro_x, icm42688_gyro_y, icm42688_gyro_z ; - static float icm42688_acc_inv = 1, icm42688_gyro_inv = 1; void Spi_GPIO_Init() { - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - __HAL_RCC_GPIOB_CLK_ENABLE(); - - /*Configure GPIO pins : PBPin PB12 */ - GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 |GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PB14 */ - GPIO_InitStruct.Pin = GPIO_PIN_14; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitTypeDef GPIO_InitStruct = {0}; + __HAL_RCC_GPIOB_CLK_ENABLE(); + /*Configure GPIO pins : PBPin PB12 */ + GPIO_InitStruct.Pin = GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } void Init_ICM42688(void) { - unsigned char time; - unsigned char model; - Spi_GPIO_Init(); - // ¶ÁÈ¡ÍÓÂÝÒÇÐͺÅÍÓÂÝÒÇ×Ô¼ì - model = 0xff; - while(1) - { - Read_Datas_ICM42688(ICM42688_WHO_AM_I, &model, 1); - if(model == 0x47) - { - // ICM42688 - break; - } - ICM42688_DELAY_MS(10); - } - Write_Data_ICM42688(ICM42688_PWR_MGMT0,0x00); // ¸´Î»É豸 - ICM42688_DELAY_MS(10); // ²Ù×÷ÍêPWR¡ªMGMT0¼Ä´æÆ÷ºó200usÄÚ²»ÄÜÓÐÈκζÁд¼Ä´æÆ÷µÄ²Ù×÷ - - // ÉèÖÃICM42688¼ÓËٶȼƺÍÍÓÂÝÒǵÄÁ¿³ÌºÍÊä³öËÙÂÊ - Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G, ICM42688_AODR_32000HZ, ICM42688_GFS_2000DPS, ICM42688_GODR_32000HZ); - - Write_Data_ICM42688(ICM42688_PWR_MGMT0, 0x0f); // ÉèÖÃGYRO_MODE,ACCEL_MODEΪµÍÔëÉùģʽ - ICM42688_DELAY_MS(10); -} -/** -* -* @brief »ñµÃICM42688ÍÓÂÝÒǼÓËÙ¶È -* @param -* @return void -* @notes µ¥Î»:g(m/s^2),Óû§µ÷Óà -* Example: Get_Acc_ICM42688(); -* -**/ -void Get_Acc_ICM42688(void) -{ - unsigned char dat[6]; - Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1, dat, 6); - icm42688_acc_x = icm42688_acc_inv * (short int)(((short int)dat[0] << 8) | dat[1]); - icm42688_acc_y = icm42688_acc_inv * (short int)(((short int)dat[2] << 8) | dat[3]); - icm42688_acc_z = icm42688_acc_inv * (short int)(((short int)dat[4] << 8) | dat[5]); + printf("Init_ICM42688\r\n"); + HAL_Delay(1000); + HAL_Delay(1000); + unsigned char model; + Spi_GPIO_Init(); + // ¶ÁÈ¡ÍÓÂÝÒÇÐͺÅÍÓÂÝÒÇ×Ô¼ì + model = 0xff; + while(1) + { + Read_Datas_ICM42688(ICM42688_WHO_AM_I, &model, 1); + if(model == 0x47) + { + printf("model:%x\r\n",model); + HAL_Delay(1000); + HAL_Delay(1000); + break; + } + ICM42688_DELAY_MS(100); + } + Write_Data_ICM42688(ICM42688_PWR_MGMT0,0x00); // ¸´Î»É豸 + ICM42688_DELAY_MS(10); // ²Ù×÷ÍêPWR¡ªMGMT0¼Ä´æÆ÷ºó200usÄÚ²»ÄÜÓÐÈκζÁд¼Ä´æÆ÷µÄ²Ù×÷ + // ÉèÖÃICM42688¼ÓËٶȼƺÍÍÓÂÝÒǵÄÁ¿³ÌºÍÊä³öËÙÂÊ + Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G, ICM42688_AODR_32000HZ, ICM42688_GFS_2000DPS, ICM42688_GODR_32000HZ); + Write_Data_ICM42688(ICM42688_PWR_MGMT0, 0x0f); // ÉèÖÃGYRO_MODE,ACCEL_MODEΪµÍÔëÉùģʽ + ICM42688_DELAY_MS(10); } -/** -* -* @brief »ñµÃICM42688ÍÓÂÝÒǽǼÓËÙ¶È -* @param -* @return void -* @notes µ¥Î»Îª:¡ã/s,Óû§µ÷Óà -* Example: Get_Gyro_ICM42688(); -* -**/ -void Get_Gyro_ICM42688(void) -{ - unsigned char dat[6]; - Read_Datas_ICM42688(ICM42688_GYRO_DATA_X1, dat, 6); - icm42688_gyro_x = icm42688_gyro_inv * (short int)(((short int)dat[0] << 8) | dat[1]); - icm42688_gyro_y = icm42688_gyro_inv * (short int)(((short int)dat[2] << 8) | dat[3]); - icm42688_gyro_z = icm42688_gyro_inv * (short int)(((short int)dat[4] << 8) | dat[5]); -} - -/** -* -* @brief ÉèÖÃICM42688ÍÓÂÝÒǵÍͨÂ˲¨Æ÷´ø¿íºÍÁ¿³Ì -* @param afs // ¼ÓËٶȼÆÁ¿³Ì,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 -* @param aodr // ¼ÓËٶȼÆÊä³öËÙÂÊ,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 -* @param gfs // ÍÓÂÝÒÇÁ¿³Ì,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 -* @param godr // ÍÓÂÝÒÇÊä³öËÙÂÊ,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 -* @return void -* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ -* Example: Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G,ICM42688_AODR_32000HZ,ICM42688_GFS_2000DPS,ICM42688_GODR_32000HZ); -* -**/ void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr) { Write_Data_ICM42688(ICM42688_ACCEL_CONFIG0, (afs << 5) | (aodr + 1)); // ³õʼ»¯ACCELÁ¿³ÌºÍÊä³öËÙÂÊ(p77) @@ -308,220 +53,54 @@ void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr switch(afs) { - case ICM42688_AFS_2G: - icm42688_acc_inv = 2000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À2g - break; - case ICM42688_AFS_4G: - icm42688_acc_inv = 4000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À4g - break; - case ICM42688_AFS_8G: - icm42688_acc_inv = 8000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À8g - break; - case ICM42688_AFS_16G: - icm42688_acc_inv = 16000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À16g - break; - default: - icm42688_acc_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý - break; + case ICM42688_AFS_2G: + icm42688_acc_inv = 2000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À2g + break; + case ICM42688_AFS_4G: + icm42688_acc_inv = 4000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À4g + break; + case ICM42688_AFS_8G: + icm42688_acc_inv = 8000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À8g + break; + case ICM42688_AFS_16G: + icm42688_acc_inv = 16000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À16g + break; + default: + icm42688_acc_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý + break; } switch(gfs) { - case ICM42688_GFS_15_625DPS: - icm42688_gyro_inv = 15.625f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À15.625dps - break; - case ICM42688_GFS_31_25DPS: - icm42688_gyro_inv = 31.25f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À31.25dps - break; - case ICM42688_GFS_62_5DPS: - icm42688_gyro_inv = 62.5f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À62.5dps - break; - case ICM42688_GFS_125DPS: - icm42688_gyro_inv = 125.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À125dps - break; - case ICM42688_GFS_250DPS: - icm42688_gyro_inv = 250.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À250dps - break; - case ICM42688_GFS_500DPS: - icm42688_gyro_inv = 500.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À500dps - break; - case ICM42688_GFS_1000DPS: - icm42688_gyro_inv = 1000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À1000dps - break; - case ICM42688_GFS_2000DPS: - icm42688_gyro_inv = 2000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À2000dps - break; - default: - icm42688_gyro_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý - break; + case ICM42688_GFS_15_625DPS: + icm42688_gyro_inv = 15.625f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À15.625dps + break; + case ICM42688_GFS_31_25DPS: + icm42688_gyro_inv = 31.25f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À31.25dps + break; + case ICM42688_GFS_62_5DPS: + icm42688_gyro_inv = 62.5f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À62.5dps + break; + case ICM42688_GFS_125DPS: + icm42688_gyro_inv = 125.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À125dps + break; + case ICM42688_GFS_250DPS: + icm42688_gyro_inv = 250.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À250dps + break; + case ICM42688_GFS_500DPS: + icm42688_gyro_inv = 500.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À500dps + break; + case ICM42688_GFS_1000DPS: + icm42688_gyro_inv = 1000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À1000dps + break; + case ICM42688_GFS_2000DPS: + icm42688_gyro_inv = 2000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À2000dps + break; + default: + icm42688_gyro_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý + break; } } -/** -* -* @brief ICM42688ÍÓÂÝÒÇд8bitÊý¾Ý -* @param data Êý¾Ý -* @return void -* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ -* Example: Write_8bit_ICM42688(0x00); -* -**/ -static void Write_8bit_ICM42688(unsigned char dat) -{ - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - if(0x80 & dat) - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); - } - else - { - sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); - } - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - dat <<= 1; -} - -/** -* -* @brief ICM42688ÍÓÂÝÒǶÁ8bitÊý¾Ý -* @param data Êý¾Ý -* @return void -* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ -* Example: Read_8bit_ICM42688(dat); -* -**/ -static void Read_8bit_ICM42688(unsigned char *dat) -{ - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - *dat = *dat << 1; - *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); -} - /** * * @brief ICM42688ÍÓÂÝÒÇдÊý¾Ý @@ -534,10 +113,12 @@ static void Read_8bit_ICM42688(unsigned char *dat) **/ static void Write_Data_ICM42688(unsigned char reg, unsigned char dat) { - sys_gpio_pin_set(GPIOB,GPIO_PIN_12,0); - Write_8bit_ICM42688(reg); - Write_8bit_ICM42688(dat); - sys_gpio_pin_set(GPIOB,GPIO_PIN_12,1); + unsigned char command[2]; + command[0] = reg; + command[1] = dat; + HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,0); + HAL_SPI_Transmit(&hspi2,command, 2, 0xff); + HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,1); } /** @@ -553,11 +134,11 @@ static void Write_Data_ICM42688(unsigned char reg, unsigned char dat) **/ static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num) { - sys_gpio_pin_set(GPIOB,GPIO_PIN_12,0); reg |= 0x80; - Write_8bit_ICM42688(reg); - while(num--) Read_8bit_ICM42688(dat++); - sys_gpio_pin_set(GPIOB,GPIO_PIN_12,1); + HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,0); + HAL_SPI_Transmit(&hspi2,®, 1, 0xff ); + HAL_SPI_Receive(&hspi2,dat, num, 0xff); + HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,1); } /* ¶ÁÈ¡MPU6050Êý¾Ý²¢¼ÓÂ˲¨ */ //·µ»ØÖµ:0,Õý³£ @@ -568,72 +149,487 @@ int16_t MpuOffset[6] = {0}; //MPU6050 uint8_t MpuGetData(void) { - uint8_t i; - int res; - unsigned char buffer[12]; - Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1,buffer,12); + uint8_t i; + uint8_t buffer[12]; + Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1,buffer,12); - for(i=0;i<6;i++) - { - pMpu[i] = (((int16_t)buffer[i<<1] << 8) | buffer[(i<<1)+1])-MpuOffset[i]; /* ½«Êý¾ÝÕûΪ16bit£¬²¢¼õȥˮƽУ׼ֵ */ - if(i < 3) /* ½Ç¼ÓËÙ¶È¿¨¶ûÂüÂ˲¨ */ - { - { - static struct KalmanFilter EKF[3] = {{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543}}; - kalmanfiter(&EKF[i],(float)pMpu[i]); - pMpu[i] = (int16_t)EKF[i].Out; - } - } - if(i > 2) /* ½ÇËÙ¶ÈÒ»½×»¥²¹Â˲¨ */ - { - uint8_t k=i-3; - const float factor = 0.15f; - static float tBuff[3]; - - pMpu[i] = tBuff[k] = tBuff[k] * (1 - factor) + pMpu[i] * factor; - } - } - return 0; -} - -void get_IMU(float *pitch,float *roll) -{ - *roll = atan2(ICM42688.accY, ICM42688.accZ) * 180.0 / _PI; - *pitch = atan2(-ICM42688.accX, sqrt(ICM42688.accX * ICM42688.accY + ICM42688.accZ * ICM42688.accZ)) * 180.0 / _PI; - -// *roll = atan2(ICM42688.accY, ICM42688.accZ); -// *pitch = atan2(-ICM42688.accX, sqrt(ICM42688.accX * ICM42688.accY + ICM42688.accZ * ICM42688.accZ)); -} - -/** -ÉèÖÃÒý½Åµçƽ - */ -void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status) -{ - if (status & 0X01) + for(i=0;i<6;i++) { - p_gpiox->BSRR |= pinx; - } - else - { - p_gpiox->BSRR |= (uint32_t)pinx << 16; - } -} + pMpu[i] = (((int16_t)buffer[i<<1] << 8) | buffer[(i<<1)+1])-MpuOffset[i]; /* ½«Êý¾ÝÕûΪ16bit£¬²¢¼õȥˮƽУ׼ֵ */ + if(i < 3) /* ½Ç¼ÓËÙ¶È¿¨¶ûÂüÂ˲¨ */ + { + { + static struct KalmanFilter EKF[3] = {{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543}}; + kalmanfiter(&EKF[i],(float)pMpu[i]); + pMpu[i] = (int16_t)EKF[i].Out; + } + } + if(i > 2) /* ½ÇËÙ¶ÈÒ»½×»¥²¹Â˲¨ */ + { + uint8_t k=i-3; + const float factor = 0.15f; + static float tBuff[3]; -/** - * ¶ÁÈ¡Òý½Åµçƽ - */ -uint8_t sys_gpio_pin_get(GPIO_TypeDef *p_gpiox, uint16_t pinx) -{ - if (p_gpiox->IDR & pinx) - { - return 1; - } - else - { - return 0; + pMpu[i] = tBuff[k] = tBuff[k] * (1 - factor) + pMpu[i] * factor; + } } + return 0; } + + + + + + + + + + +// +// +/////////////Ä£Äâspi°æ±¾ +//#include "icm42688.h" +// +//#include "kalman.h" +//#include "alldata.h" +// +//// ICM42688¼ÓËٶȼÆÊý¾Ý +//float icm42688_acc_x, icm42688_acc_y, icm42688_acc_z ; +//// ICM42688½Ç¼ÓËÙ¶ÈÊý¾Ý +//float icm42688_gyro_x, icm42688_gyro_y, icm42688_gyro_z ; +// +//static float icm42688_acc_inv = 1, icm42688_gyro_inv = 1; +// +//void Spi_GPIO_Init() +//{ +// +// GPIO_InitTypeDef GPIO_InitStruct = {0}; +// __HAL_RCC_GPIOB_CLK_ENABLE(); +// +// /*Configure GPIO pins : PBPin PB12 */ +// GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 |GPIO_PIN_15; +// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// GPIO_InitStruct.Pull = GPIO_NOPULL; +// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; +// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); +// +// /*Configure GPIO pins : PBPin PB14 */ +// GPIO_InitStruct.Pin = GPIO_PIN_14; +// GPIO_InitStruct.Mode = GPIO_MODE_INPUT; +// GPIO_InitStruct.Pull = GPIO_NOPULL; +// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); +//} +// +//void Init_ICM42688(void) +//{ +// unsigned char time; +// unsigned char model; +// Spi_GPIO_Init(); +// // ¶ÁÈ¡ÍÓÂÝÒÇÐͺÅÍÓÂÝÒÇ×Ô¼ì +// model = 0xff; +// while(1) +// { +// Read_Datas_ICM42688(ICM42688_WHO_AM_I, &model, 1); +// if(model == 0x47) +// { +// // ICM42688 +// break; +// } +// ICM42688_DELAY_MS(10); +// } +// Write_Data_ICM42688(ICM42688_PWR_MGMT0,0x00); // ¸´Î»É豸 +// ICM42688_DELAY_MS(10); // ²Ù×÷ÍêPWR¡ªMGMT0¼Ä´æÆ÷ºó200usÄÚ²»ÄÜÓÐÈκζÁд¼Ä´æÆ÷µÄ²Ù×÷ +// +// // ÉèÖÃICM42688¼ÓËٶȼƺÍÍÓÂÝÒǵÄÁ¿³ÌºÍÊä³öËÙÂÊ +// Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G, ICM42688_AODR_32000HZ, ICM42688_GFS_2000DPS, ICM42688_GODR_32000HZ); +// +// Write_Data_ICM42688(ICM42688_PWR_MGMT0, 0x0f); // ÉèÖÃGYRO_MODE,ACCEL_MODEΪµÍÔëÉùģʽ +// ICM42688_DELAY_MS(10); +//} +///** +//* +//* @brief »ñµÃICM42688ÍÓÂÝÒǼÓËÙ¶È +//* @param +//* @return void +//* @notes µ¥Î»:g(m/s^2),Óû§µ÷Óà +//* Example: Get_Acc_ICM42688(); +//* +//**/ +//void Get_Acc_ICM42688(void) +//{ +// unsigned char dat[6]; +// Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1, dat, 6); +// icm42688_acc_x = icm42688_acc_inv * (short int)(((short int)dat[0] << 8) | dat[1]); +// icm42688_acc_y = icm42688_acc_inv * (short int)(((short int)dat[2] << 8) | dat[3]); +// icm42688_acc_z = icm42688_acc_inv * (short int)(((short int)dat[4] << 8) | dat[5]); +//} +// +///** +//* +//* @brief »ñµÃICM42688ÍÓÂÝÒǽǼÓËÙ¶È +//* @param +//* @return void +//* @notes µ¥Î»Îª:¡ã/s,Óû§µ÷Óà +//* Example: Get_Gyro_ICM42688(); +//* +//**/ +//void Get_Gyro_ICM42688(void) +//{ +// unsigned char dat[6]; +// Read_Datas_ICM42688(ICM42688_GYRO_DATA_X1, dat, 6); +// icm42688_gyro_x = icm42688_gyro_inv * (short int)(((short int)dat[0] << 8) | dat[1]); +// icm42688_gyro_y = icm42688_gyro_inv * (short int)(((short int)dat[2] << 8) | dat[3]); +// icm42688_gyro_z = icm42688_gyro_inv * (short int)(((short int)dat[4] << 8) | dat[5]); +//} +// +///** +//* +//* @brief ÉèÖÃICM42688ÍÓÂÝÒǵÍͨÂ˲¨Æ÷´ø¿íºÍÁ¿³Ì +//* @param afs // ¼ÓËٶȼÆÁ¿³Ì,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 +//* @param aodr // ¼ÓËٶȼÆÊä³öËÙÂÊ,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 +//* @param gfs // ÍÓÂÝÒÇÁ¿³Ì,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 +//* @param godr // ÍÓÂÝÒÇÊä³öËÙÂÊ,¿ÉÔÚdmx_icm42688.hÎļþÀïö¾Ù¶¨ÒåÖв鿴 +//* @return void +//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ +//* Example: Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G,ICM42688_AODR_32000HZ,ICM42688_GFS_2000DPS,ICM42688_GODR_32000HZ); +//* +//**/ +//void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr) +//{ +// Write_Data_ICM42688(ICM42688_ACCEL_CONFIG0, (afs << 5) | (aodr + 1)); // ³õʼ»¯ACCELÁ¿³ÌºÍÊä³öËÙÂÊ(p77) +// Write_Data_ICM42688(ICM42688_GYRO_CONFIG0, (gfs << 5) | (godr + 1)); // ³õʼ»¯GYROÁ¿³ÌºÍÊä³öËÙÂÊ(p76) +// +// switch(afs) +// { +// case ICM42688_AFS_2G: +// icm42688_acc_inv = 2000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À2g +// break; +// case ICM42688_AFS_4G: +// icm42688_acc_inv = 4000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À4g +// break; +// case ICM42688_AFS_8G: +// icm42688_acc_inv = 8000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À8g +// break; +// case ICM42688_AFS_16G: +// icm42688_acc_inv = 16000 / 32768.0f; // ¼ÓËٶȼÆÁ¿³ÌΪ:¡À16g +// break; +// default: +// icm42688_acc_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý +// break; +// } +// switch(gfs) +// { +// case ICM42688_GFS_15_625DPS: +// icm42688_gyro_inv = 15.625f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À15.625dps +// break; +// case ICM42688_GFS_31_25DPS: +// icm42688_gyro_inv = 31.25f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À31.25dps +// break; +// case ICM42688_GFS_62_5DPS: +// icm42688_gyro_inv = 62.5f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À62.5dps +// break; +// case ICM42688_GFS_125DPS: +// icm42688_gyro_inv = 125.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À125dps +// break; +// case ICM42688_GFS_250DPS: +// icm42688_gyro_inv = 250.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À250dps +// break; +// case ICM42688_GFS_500DPS: +// icm42688_gyro_inv = 500.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À500dps +// break; +// case ICM42688_GFS_1000DPS: +// icm42688_gyro_inv = 1000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À1000dps +// break; +// case ICM42688_GFS_2000DPS: +// icm42688_gyro_inv = 2000.0f / 32768.0f; // ÍÓÂÝÒÇÁ¿³ÌΪ:¡À2000dps +// break; +// default: +// icm42688_gyro_inv = 1; // ²»×ª»¯ÎªÊµ¼ÊÊý¾Ý +// break; +// } +//} +// +///** +//* +//* @brief ICM42688ÍÓÂÝÒÇд8bitÊý¾Ý +//* @param data Êý¾Ý +//* @return void +//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ +//* Example: Write_8bit_ICM42688(0x00); +//* +//**/ +//static void Write_8bit_ICM42688(unsigned char dat) +//{ +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// if(0x80 & dat) +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,1); +// } +// else +// { +// sys_gpio_pin_set(GPIOB,GPIO_PIN_15,0); +// } +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// dat <<= 1; +//} +// +///** +//* +//* @brief ICM42688ÍÓÂÝÒǶÁ8bitÊý¾Ý +//* @param data Êý¾Ý +//* @return void +//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ +//* Example: Read_8bit_ICM42688(dat); +//* +//**/ +//static void Read_8bit_ICM42688(unsigned char *dat) +//{ +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +// +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); +// *dat = *dat << 1; +// *dat |=sys_gpio_pin_get(GPIOB,GPIO_PIN_14); +// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); +//} +// +///** +//* +//* @brief ICM42688ÍÓÂÝÒÇдÊý¾Ý +//* @param reg ¼Ä´æÆ÷ +//* @param data ÐèҪд½ø¸Ã¼Ä´æÆ÷µÄÊý¾Ý +//* @return void +//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ +//* Example: Write_Data_ICM42688(0x00,0x00); +//* +//**/ +//static void Write_Data_ICM42688(unsigned char reg, unsigned char dat) +//{ +// sys_gpio_pin_set(GPIOB,GPIO_PIN_12,0); +// Write_8bit_ICM42688(reg); +// Write_8bit_ICM42688(dat); +// sys_gpio_pin_set(GPIOB,GPIO_PIN_12,1); +//} +// +///** +//* +//* @brief ICM42688ÍÓÂÝÒǶÁÊý¾Ý +//* @param reg ¼Ä´æÆ÷ +//* @param data °Ñ¶Á³öµÄÊý¾Ý´æÈëdata +//* @param num Êý¾Ý¸öÊý +//* @return void +//* @notes ICM42688.cÎļþÄÚ²¿µ÷ÓÃ,Óû§ÎÞÐèµ÷Óó¢ÊÔ +//* Example: Read_Datas_ICM42688(0x00,0x00,1); +//* +//**/ +//static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num) +//{ +// sys_gpio_pin_set(GPIOB,GPIO_PIN_12,0); +// reg |= 0x80; +// Write_8bit_ICM42688(reg); +// while(num--) Read_8bit_ICM42688(dat++); +// sys_gpio_pin_set(GPIOB,GPIO_PIN_12,1); +//} +///* ¶ÁÈ¡MPU6050Êý¾Ý²¢¼ÓÂ˲¨ */ +////·µ»ØÖµ:0,Õý³£ +////ÆäËû,´íÎó´úÂë +//_st_Mpu ICM42688; +//static volatile int16_t *pMpu = (int16_t *)&ICM42688; +//int16_t MpuOffset[6] = {0}; //MPU6050²¹³¥ÊýÖµ +// +//uint8_t MpuGetData(void) +//{ +// uint8_t i; +// int res; +// unsigned char buffer[12]; +// Read_Datas_ICM42688(ICM42688_ACCEL_DATA_X1,buffer,12); +// +// for(i=0;i<6;i++) +// { +// pMpu[i] = (((int16_t)buffer[i<<1] << 8) | buffer[(i<<1)+1])-MpuOffset[i]; /* ½«Êý¾ÝÕûΪ16bit£¬²¢¼õȥˮƽУ׼ֵ */ +// if(i < 3) /* ½Ç¼ÓËÙ¶È¿¨¶ûÂüÂ˲¨ */ +// { +// { +// static struct KalmanFilter EKF[3] = {{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543},{0.02,0,0,0,0.001,0.543}}; +// kalmanfiter(&EKF[i],(float)pMpu[i]); +// pMpu[i] = (int16_t)EKF[i].Out; +// } +// } +// if(i > 2) /* ½ÇËÙ¶ÈÒ»½×»¥²¹Â˲¨ */ +// { +// uint8_t k=i-3; +// const float factor = 0.15f; +// static float tBuff[3]; +// +// pMpu[i] = tBuff[k] = tBuff[k] * (1 - factor) + pMpu[i] * factor; +// } +// } +// return 0; +//} +// +//void get_IMU(float *pitch,float *roll) +//{ +// *roll = atan2(ICM42688.accY, ICM42688.accZ) * 180.0 / _PI; +// *pitch = atan2(-ICM42688.accX, sqrt(ICM42688.accX * ICM42688.accY + ICM42688.accZ * ICM42688.accZ)) * 180.0 / _PI; +// +//// *roll = atan2(ICM42688.accY, ICM42688.accZ); +//// *pitch = atan2(-ICM42688.accX, sqrt(ICM42688.accX * ICM42688.accY + ICM42688.accZ * ICM42688.accZ)); +//} +// +///** +//ÉèÖÃÒý½Åµçƽ +// */ +//void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status) +//{ +// if (status & 0X01) +// { +// p_gpiox->BSRR |= pinx; +// } +// else +// { +// p_gpiox->BSRR |= (uint32_t)pinx << 16; +// } +//} +// +///** +// * ¶ÁÈ¡Òý½Åµçƽ +// */ +//uint8_t sys_gpio_pin_get(GPIO_TypeDef *p_gpiox, uint16_t pinx) +//{ +// if (p_gpiox->IDR & pinx) +// { +// return 1; +// } +// else +// { +// return 0; +// } +//} +// +// +// diff --git a/IMU/icm42688.h b/IMU/icm42688.h index 9a0d450..35a6cf1 100644 --- a/IMU/icm42688.h +++ b/IMU/icm42688.h @@ -1,212 +1,10 @@ -//#ifndef _DMX_ICM42688_H_ -//#define _DMX_ICM42688_H_ -//#include "stm32h7xx_hal.h" -//#include "mymain.h" -//#define ICM42688_DELAY_MS(time) (HAL_Delay(time)) -// -// -//enum icm42688_afs -//{ -// ICM42688_AFS_16G,// default -// ICM42688_AFS_8G, -// ICM42688_AFS_4G, -// ICM42688_AFS_2G, -// NUM_ICM42688__AFS -//}; -// -//enum icm42688_aodr -//{ -// ICM42688_AODR_32000HZ, -// ICM42688_AODR_16000HZ, -// ICM42688_AODR_8000HZ, -// ICM42688_AODR_4000HZ, -// ICM42688_AODR_2000HZ, -// ICM42688_AODR_1000HZ,// default -// ICM42688_AODR_200HZ, -// ICM42688_AODR_100HZ, -// ICM42688_AODR_50HZ, -// ICM42688_AODR_25HZ, -// ICM42688_AODR_12_5HZ, -// ICM42688_AODR_6_25HZ, -// ICM42688_AODR_3_125HZ, -// ICM42688_AODR_1_5625HZ, -// ICM42688_AODR_500HZ, -// NUM_ICM42688_AODR -//}; -// -//enum icm42688_gfs -//{ -// ICM42688_GFS_2000DPS,// default -// ICM42688_GFS_1000DPS, -// ICM42688_GFS_500DPS, -// ICM42688_GFS_250DPS, -// ICM42688_GFS_125DPS, -// ICM42688_GFS_62_5DPS, -// ICM42688_GFS_31_25DPS, -// ICM42688_GFS_15_625DPS, -// NUM_ICM42688_GFS -//}; -//enum icm42688_godr -//{ -// ICM42688_GODR_32000HZ, -// ICM42688_GODR_16000HZ, -// ICM42688_GODR_8000HZ, -// ICM42688_GODR_4000HZ, -// ICM42688_GODR_2000HZ, -// ICM42688_GODR_1000HZ,// default -// ICM42688_GODR_200HZ, -// ICM42688_GODR_100HZ, -// ICM42688_GODR_50HZ, -// ICM42688_GODR_25HZ, -// ICM42688_GODR_12_5HZ, -// ICM42688_GODR_X0HZ, -// ICM42688_GODR_X1HZ, -// ICM42688_GODR_X2HZ, -// ICM42688_GODR_500HZ, -// NUM_ICM42688_GODR -//}; -// -// -//// ICM42688Bank0�ڲ���ַ -//#define ICM42688_DEVICE_CONFIG 0x11 -//#define ICM42688_DRIVE_CONFIG 0x13 -//#define ICM42688_INT_CONFIG 0x14 -//#define ICM42688_FIFO_CONFIG 0x16 -//#define ICM42688_TEMP_DATA1 0x1D -//#define ICM42688_TEMP_DATA0 0x1E -//#define ICM42688_ACCEL_DATA_X1 0x1F -//#define ICM42688_ACCEL_DATA_X0 0x20 -//#define ICM42688_ACCEL_DATA_Y1 0x21 -//#define ICM42688_ACCEL_DATA_Y0 0x22 -//#define ICM42688_ACCEL_DATA_Z1 0x23 -//#define ICM42688_ACCEL_DATA_Z0 0x24 -//#define ICM42688_GYRO_DATA_X1 0x25 -//#define ICM42688_GYRO_DATA_X0 0x26 -//#define ICM42688_GYRO_DATA_Y1 0x27 -//#define ICM42688_GYRO_DATA_Y0 0x28 -//#define ICM42688_GYRO_DATA_Z1 0x29 -//#define ICM42688_GYRO_DATA_Z0 0x2A -//#define ICM42688_TMST_FSYNCH 0x2B -//#define ICM42688_TMST_FSYNCL 0x2C -//#define ICM42688_INT_STATUS 0x2D -//#define ICM42688_FIFO_COUNTH 0x2E -//#define ICM42688_FIFO_COUNTL 0x2F -//#define ICM42688_FIFO_DATA 0x30 -//#define ICM42688_APEX_DATA0 0x31 -//#define ICM42688_APEX_DATA1 0x32 -//#define ICM42688_APEX_DATA2 0x33 -//#define ICM42688_APEX_DATA3 0x34 -//#define ICM42688_APEX_DATA4 0x35 -//#define ICM42688_APEX_DATA5 0x36 -//#define ICM42688_INT_STATUS2 0x37 -//#define ICM42688_INT_STATUS3 0x38 -//#define ICM42688_SIGNAL_PATH_RESET 0x4B -//#define ICM42688_INTF_CONFIG0 0x4C -//#define ICM42688_INTF_CONFIG1 0x4D -//#define ICM42688_PWR_MGMT0 0x4E -//#define ICM42688_GYRO_CONFIG0 0x4F -//#define ICM42688_ACCEL_CONFIG0 0x50 -//#define ICM42688_GYRO_CONFIG1 0x51 -//#define ICM42688_GYRO_ACCEL_CONFIG0 0x52 -//#define ICM42688_ACCEL_CONFIG1 0x53 -//#define ICM42688_TMST_CONFIG 0x54 -//#define ICM42688_APEX_CONFIG0 0x56 -//#define ICM42688_SMD_CONFIG 0x57 -//#define ICM42688_FIFO_CONFIG1 0x5F -//#define ICM42688_FIFO_CONFIG2 0x60 -//#define ICM42688_FIFO_CONFIG3 0x61 -//#define ICM42688_FSYNC_CONFIG 0x62 -//#define ICM42688_INT_CONFIG0 0x63 -//#define ICM42688_INT_CONFIG1 0x64 -//#define ICM42688_INT_SOURCE0 0x65 -//#define ICM42688_INT_SOURCE1 0x66 -//#define ICM42688_INT_SOURCE3 0x68 -//#define ICM42688_INT_SOURCE4 0x69 -//#define ICM42688_FIFO_LOST_PKT0 0x6C -//#define ICM42688_FIFO_LOST_PKT1 0x6D -//#define ICM42688_SELF_TEST_CONFIG 0x70 -//#define ICM42688_WHO_AM_I 0x75 -//#define ICM42688_REG_BANK_SEL 0x76 // Banks -//#define ICM42688_SENSOR_CONFIG0 0x03 -//#define ICM42688_GYRO_CONFIG_STATIC2 0x0B -//#define ICM42688_GYRO_CONFIG_STATIC3 0x0C -//#define ICM42688_GYRO_CONFIG_STATIC4 0x0D -//#define ICM42688_GYRO_CONFIG_STATIC5 0x0E -//#define ICM42688_GYRO_CONFIG_STATIC6 0x0F -//#define ICM42688_GYRO_CONFIG_STATIC7 0x10 -//#define ICM42688_GYRO_CONFIG_STATIC8 0x11 -//#define ICM42688_GYRO_CONFIG_STATIC9 0x12 -//#define ICM42688_GYRO_CONFIG_STATIC10 0x13 -//#define ICM42688_XG_ST_DATA 0x5F -//#define ICM42688_YG_ST_DATA 0x60 -//#define ICM42688_ZG_ST_DATA 0x61 -//#define ICM42688_TMSTVAL0 0x62 -//#define ICM42688_TMSTVAL1 0x63 -//#define ICM42688_TMSTVAL2 0x64 -//#define ICM42688_INTF_CONFIG4 0x7A -//#define ICM42688_INTF_CONFIG5 0x7B -//#define ICM42688_INTF_CONFIG6 0x7C -// -// -//static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num); -//static void Write_Data_ICM42688(unsigned char reg, unsigned char dat); -//void Init_ICM42688(void); -////void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status); -//void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr); -//uint8_t MpuGetData(void); -// -// -//#endif -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifndef _DMX_ICM42688_H_ #define _DMX_ICM42688_H_ #include "stm32h7xx_hal.h" #include "mymain.h" #define ICM42688_DELAY_MS(time) (HAL_Delay(time)) -extern float icm42688_acc_x, icm42688_acc_y, icm42688_acc_z ; // ����ICM42688���ٶȼ����� -extern float icm42688_gyro_x, icm42688_gyro_y, icm42688_gyro_z ; // ����ICM42688�Ǽ��ٶ����� -static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num); -static void Write_Data_ICM42688(unsigned char reg, unsigned char dat); + enum icm42688_afs { ICM42688_AFS_16G,// default @@ -268,58 +66,7 @@ enum icm42688_godr NUM_ICM42688_GODR }; -void gpio_init(void); -/** -* -* @brief ICM42688�����dz�ʼ�� -* @param -* @return void -* @notes �û����� -* Example: Init_ICM42688(); -* -**/ -void Init_ICM42688(void); -//void get_IMU(float accx,float accy,float accz,float *pitch,float *roll); -void get_IMU(float *pitch,float *roll); -uint8_t sys_gpio_pin_get(GPIO_TypeDef *p_gpiox, uint16_t pinx); -void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status); -/** -* -* @brief ���ICM42688�����Ǽ��ٶ� -* @param -* @return void -* @notes ��λ:g(m/s^2),�û����� -* Example: Get_Acc_ICM42688(); -* -**/ -void Get_Acc_ICM42688(void); - -/** -* -* @brief ���ICM42688�����ǽǼ��ٶ� -* @param -* @return void -* @notes ��λΪ:��/s,�û����� -* Example: Get_Gyro_ICM42688(); -* -**/ -void Get_Gyro_ICM42688(void); - -/** -* -* @brief ����ICM42688�����ǵ�ͨ�˲������������ -* @param afs // ���ٶȼ�����,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 -* @param aodr // ���ٶȼ��������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 -* @param gfs // ����������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 -* @param godr // �������������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 -* @return void -* @notes ICM42688.c�ļ��ڲ�����,�û�������ó��� -* Example: Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G,ICM42688_AODR_32000HZ,ICM42688_GFS_2000DPS,ICM42688_GODR_32000HZ); -* -**/ -void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr); -uint8_t MpuGetData(void); // ICM42688Bank0�ڲ���ַ #define ICM42688_DEVICE_CONFIG 0x11 #define ICM42688_DRIVE_CONFIG 0x13 @@ -400,5 +147,258 @@ uint8_t MpuGetData(void); #define ICM42688_INTF_CONFIG5 0x7B #define ICM42688_INTF_CONFIG6 0x7C + +static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num); +static void Write_Data_ICM42688(unsigned char reg, unsigned char dat); +void Init_ICM42688(void); +//void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status); +void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr); +uint8_t MpuGetData(void); + + #endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// +//#ifndef _DMX_ICM42688_H_ +//#define _DMX_ICM42688_H_ +//#include "stm32h7xx_hal.h" +//#include "mymain.h" +//#define ICM42688_DELAY_MS(time) (HAL_Delay(time)) +// +//extern float icm42688_acc_x, icm42688_acc_y, icm42688_acc_z ; // ����ICM42688���ٶȼ����� +//extern float icm42688_gyro_x, icm42688_gyro_y, icm42688_gyro_z ; // ����ICM42688�Ǽ��ٶ����� +//static void Read_Datas_ICM42688(unsigned char reg, unsigned char *dat, unsigned int num); +//static void Write_Data_ICM42688(unsigned char reg, unsigned char dat); +//enum icm42688_afs +//{ +// ICM42688_AFS_16G,// default +// ICM42688_AFS_8G, +// ICM42688_AFS_4G, +// ICM42688_AFS_2G, +// NUM_ICM42688__AFS +//}; +// +//enum icm42688_aodr +//{ +// ICM42688_AODR_32000HZ, +// ICM42688_AODR_16000HZ, +// ICM42688_AODR_8000HZ, +// ICM42688_AODR_4000HZ, +// ICM42688_AODR_2000HZ, +// ICM42688_AODR_1000HZ,// default +// ICM42688_AODR_200HZ, +// ICM42688_AODR_100HZ, +// ICM42688_AODR_50HZ, +// ICM42688_AODR_25HZ, +// ICM42688_AODR_12_5HZ, +// ICM42688_AODR_6_25HZ, +// ICM42688_AODR_3_125HZ, +// ICM42688_AODR_1_5625HZ, +// ICM42688_AODR_500HZ, +// NUM_ICM42688_AODR +//}; +// +//enum icm42688_gfs +//{ +// ICM42688_GFS_2000DPS,// default +// ICM42688_GFS_1000DPS, +// ICM42688_GFS_500DPS, +// ICM42688_GFS_250DPS, +// ICM42688_GFS_125DPS, +// ICM42688_GFS_62_5DPS, +// ICM42688_GFS_31_25DPS, +// ICM42688_GFS_15_625DPS, +// NUM_ICM42688_GFS +//}; +//enum icm42688_godr +//{ +// ICM42688_GODR_32000HZ, +// ICM42688_GODR_16000HZ, +// ICM42688_GODR_8000HZ, +// ICM42688_GODR_4000HZ, +// ICM42688_GODR_2000HZ, +// ICM42688_GODR_1000HZ,// default +// ICM42688_GODR_200HZ, +// ICM42688_GODR_100HZ, +// ICM42688_GODR_50HZ, +// ICM42688_GODR_25HZ, +// ICM42688_GODR_12_5HZ, +// ICM42688_GODR_X0HZ, +// ICM42688_GODR_X1HZ, +// ICM42688_GODR_X2HZ, +// ICM42688_GODR_500HZ, +// NUM_ICM42688_GODR +//}; +// +//void gpio_init(void); +// +///** +//* +//* @brief ICM42688�����dz�ʼ�� +//* @param +//* @return void +//* @notes �û����� +//* Example: Init_ICM42688(); +//* +//**/ +//void Init_ICM42688(void); +////void get_IMU(float accx,float accy,float accz,float *pitch,float *roll); +//void get_IMU(float *pitch,float *roll); +//uint8_t sys_gpio_pin_get(GPIO_TypeDef *p_gpiox, uint16_t pinx); +//void sys_gpio_pin_set(GPIO_TypeDef *p_gpiox, uint16_t pinx, uint8_t status); +///** +//* +//* @brief ���ICM42688�����Ǽ��ٶ� +//* @param +//* @return void +//* @notes ��λ:g(m/s^2),�û����� +//* Example: Get_Acc_ICM42688(); +//* +//**/ +//void Get_Acc_ICM42688(void); +// +///** +//* +//* @brief ���ICM42688�����ǽǼ��ٶ� +//* @param +//* @return void +//* @notes ��λΪ:��/s,�û����� +//* Example: Get_Gyro_ICM42688(); +//* +//**/ +//void Get_Gyro_ICM42688(void); +// +///** +//* +//* @brief ����ICM42688�����ǵ�ͨ�˲������������ +//* @param afs // ���ٶȼ�����,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 +//* @param aodr // ���ٶȼ��������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 +//* @param gfs // ����������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 +//* @param godr // �������������,����dmx_icm42688.h�ļ���ö�ٶ����в鿴 +//* @return void +//* @notes ICM42688.c�ļ��ڲ�����,�û�������ó��� +//* Example: Set_LowpassFilter_Range_ICM42688(ICM42688_AFS_16G,ICM42688_AODR_32000HZ,ICM42688_GFS_2000DPS,ICM42688_GODR_32000HZ); +//* +//**/ +//void Set_LowpassFilter_Range_ICM42688(enum icm42688_afs afs, enum icm42688_aodr aodr, enum icm42688_gfs gfs, enum icm42688_godr godr); +//uint8_t MpuGetData(void); +//// ICM42688Bank0�ڲ���ַ +//#define ICM42688_DEVICE_CONFIG 0x11 +//#define ICM42688_DRIVE_CONFIG 0x13 +//#define ICM42688_INT_CONFIG 0x14 +//#define ICM42688_FIFO_CONFIG 0x16 +//#define ICM42688_TEMP_DATA1 0x1D +//#define ICM42688_TEMP_DATA0 0x1E +//#define ICM42688_ACCEL_DATA_X1 0x1F +//#define ICM42688_ACCEL_DATA_X0 0x20 +//#define ICM42688_ACCEL_DATA_Y1 0x21 +//#define ICM42688_ACCEL_DATA_Y0 0x22 +//#define ICM42688_ACCEL_DATA_Z1 0x23 +//#define ICM42688_ACCEL_DATA_Z0 0x24 +//#define ICM42688_GYRO_DATA_X1 0x25 +//#define ICM42688_GYRO_DATA_X0 0x26 +//#define ICM42688_GYRO_DATA_Y1 0x27 +//#define ICM42688_GYRO_DATA_Y0 0x28 +//#define ICM42688_GYRO_DATA_Z1 0x29 +//#define ICM42688_GYRO_DATA_Z0 0x2A +//#define ICM42688_TMST_FSYNCH 0x2B +//#define ICM42688_TMST_FSYNCL 0x2C +//#define ICM42688_INT_STATUS 0x2D +//#define ICM42688_FIFO_COUNTH 0x2E +//#define ICM42688_FIFO_COUNTL 0x2F +//#define ICM42688_FIFO_DATA 0x30 +//#define ICM42688_APEX_DATA0 0x31 +//#define ICM42688_APEX_DATA1 0x32 +//#define ICM42688_APEX_DATA2 0x33 +//#define ICM42688_APEX_DATA3 0x34 +//#define ICM42688_APEX_DATA4 0x35 +//#define ICM42688_APEX_DATA5 0x36 +//#define ICM42688_INT_STATUS2 0x37 +//#define ICM42688_INT_STATUS3 0x38 +//#define ICM42688_SIGNAL_PATH_RESET 0x4B +//#define ICM42688_INTF_CONFIG0 0x4C +//#define ICM42688_INTF_CONFIG1 0x4D +//#define ICM42688_PWR_MGMT0 0x4E +//#define ICM42688_GYRO_CONFIG0 0x4F +//#define ICM42688_ACCEL_CONFIG0 0x50 +//#define ICM42688_GYRO_CONFIG1 0x51 +//#define ICM42688_GYRO_ACCEL_CONFIG0 0x52 +//#define ICM42688_ACCEL_CONFIG1 0x53 +//#define ICM42688_TMST_CONFIG 0x54 +//#define ICM42688_APEX_CONFIG0 0x56 +//#define ICM42688_SMD_CONFIG 0x57 +//#define ICM42688_FIFO_CONFIG1 0x5F +//#define ICM42688_FIFO_CONFIG2 0x60 +//#define ICM42688_FIFO_CONFIG3 0x61 +//#define ICM42688_FSYNC_CONFIG 0x62 +//#define ICM42688_INT_CONFIG0 0x63 +//#define ICM42688_INT_CONFIG1 0x64 +//#define ICM42688_INT_SOURCE0 0x65 +//#define ICM42688_INT_SOURCE1 0x66 +//#define ICM42688_INT_SOURCE3 0x68 +//#define ICM42688_INT_SOURCE4 0x69 +//#define ICM42688_FIFO_LOST_PKT0 0x6C +//#define ICM42688_FIFO_LOST_PKT1 0x6D +//#define ICM42688_SELF_TEST_CONFIG 0x70 +//#define ICM42688_WHO_AM_I 0x75 +//#define ICM42688_REG_BANK_SEL 0x76 // Banks +//#define ICM42688_SENSOR_CONFIG0 0x03 +//#define ICM42688_GYRO_CONFIG_STATIC2 0x0B +//#define ICM42688_GYRO_CONFIG_STATIC3 0x0C +//#define ICM42688_GYRO_CONFIG_STATIC4 0x0D +//#define ICM42688_GYRO_CONFIG_STATIC5 0x0E +//#define ICM42688_GYRO_CONFIG_STATIC6 0x0F +//#define ICM42688_GYRO_CONFIG_STATIC7 0x10 +//#define ICM42688_GYRO_CONFIG_STATIC8 0x11 +//#define ICM42688_GYRO_CONFIG_STATIC9 0x12 +//#define ICM42688_GYRO_CONFIG_STATIC10 0x13 +//#define ICM42688_XG_ST_DATA 0x5F +//#define ICM42688_YG_ST_DATA 0x60 +//#define ICM42688_ZG_ST_DATA 0x61 +//#define ICM42688_TMSTVAL0 0x62 +//#define ICM42688_TMSTVAL1 0x63 +//#define ICM42688_TMSTVAL2 0x64 +//#define ICM42688_INTF_CONFIG4 0x7A +//#define ICM42688_INTF_CONFIG5 0x7B +//#define ICM42688_INTF_CONFIG6 0x7C +// +//#endif +//