ICM20602 6轴IMU单元类似MPU6050资料分享

[复制链接]
8263|4
 楼主| cornrn 发表于 2017-12-8 21:49 | 显示全部楼层 |阅读模式
AN-IVS-0001EVB-00-v1.4.pdf (1.35 MB, 下载次数: 84)
DS-000176-ICM-20602-v1.0.pdf (1.3 MB, 下载次数: 103)
eMD_Software_Guide_ICM20602.pdf (1.12 MB, 下载次数: 83)
ICM-20602-Product-Brief-v1.0.pdf (321.82 KB, 下载次数: 98)
InvenSense-MEMS-Handling.pdf (651.77 KB, 下载次数: 71)





  1. /**
  2.   ******************************************************************************
  3.   * File Name          : icm20602_driver.c
  4.   * Description        : This file provides code for the icm_20602 .
  5.   ******************************************************************************
  6.   *
  7.   * COPYRIGHT(c) 2016 aibird
  8.   *
  9.   ******************************************************************************
  10.         *
  11.         * Author:
  12.         *
  13.         ******************************************************************************
  14.         */
  15.        
  16. /* Includes ------------------------------------------------------------------*/
  17. #include "stm32f1xx_hal.h"
  18. #include "icm20602_driver.h"

  19. #include "soft_iic.h"



  20. /* Private define ------------------------------------------------------------*/
  21. /** @defgroup ICM20602 Device And Register Address
  22.   
  23.   */

  24. #define                ICM20602_DEVICE_ADDRESS                                                                                (0xD0)  //0xD0@SA0=0  0xD2@SA0=1

  25. #define                ICM20602_ID_REG_ADDRESS                                                                                (0x75)  //who am i

  26. /*ICM20602配置寄存器*/
  27. #define         ICM20602_CFG_REG_ADDR                                                                                        (0x1A)
  28. #define         ICM20602_GYRO_CFG_REG_ADDR                                                                (0x1B)
  29. #define         ICM20602_ACC_CFG_REG_ADDR                                                                        (0x1C)
  30. #define         ICM20602_ACC_CFG2_REG_ADDR                                                                (0x1D)
  31. #define         ICM20602_GYRO_LPM_CFG_REG_ADDR                                                (0x1E)


  32. /*ICM20602的数据寄存器*/
  33. #define         ICM20602_ACC_XOUT_H_REG_ADDR                                                        (0x3B)
  34. #define         ICM20602_ACC_XOUT_L_REG_ADDR                                                        (0x3C)
  35. #define         ICM20602_ACC_YOUT_H_REG_ADDR                                                        (0x3D)
  36. #define         ICM20602_ACC_YOUT_L_REG_ADDR                                                        (0x3E)
  37. #define         ICM20602_ACC_ZOUT_H_REG_ADDR                                                        (0x3F)
  38. #define         ICM20602_ACC_ZOUT_L_REG_ADDR                                                        (0x40)

  39. #define         ICM20602_TMEP_OUT_H_REG_ADDR                                                        (0x41)
  40. #define         ICM20602_TMEP_OUT_L_REG_ADDR                                                        (0x42)

  41. #define         ICM20602_GYRO_XOUT_H_REG_ADDR                                                        (0x43)
  42. #define         ICM20602_GYRO_XOUT_L_REG_ADDR                                                        (0x44)
  43. #define         ICM20602_GYRO_YOUT_H_REG_ADDR                                                        (0x45)
  44. #define         ICM20602_GYRO_YOUT_L_REG_ADDR                                                        (0x46)
  45. #define         ICM20602_GYRO_ZOUT_H_REG_ADDR                                                        (0x47)
  46. #define         ICM20602_GYRO_ZOUT_L_REG_ADDR                                                        (0x48)

  47. /*ICM20602的电源寄存器*/
  48. #define         ICM20602_USER_CTRL_REG_ADDR                                                                (0x6A)
  49. #define         ICM20602_PWR_MGMT_1_REG_ADDR                                                        (0x6B)
  50. #define         ICM20602_PWR_MGMT_2_REG_ADDR                                                        (0x6C)


  51. /* Private variables ---------------------------------------------------------*/
  52. static                float        f_icm20602_gyro_scale = 1/16.4f;            //default 2000dps
  53. static                float        f_icm20602_acc_scale = 1/16384.f;                //default ±2g


  54. /**
  55.   * [url=home.php?mod=space&uid=247401]@brief[/url]         init mpu6050                                
  56.   */
  57. void        Init_Icm20602(I2C_HandleTypeDef *hi2c)
  58. {
  59.         uint8_t        uc_icm20602_reg_config_value_p;
  60.         uint8_t        uc_icm20602_reg_value_fdb_p;
  61.        
  62.         /**
  63.                 * ICM20602_PWR_MGMT_1_REG_ADDR
  64.                 * bit7-RST                        1-trig device reset          0-no action
  65.                 * bit6-SLEEP                1-SLEEP                                                                0-NORMAL
  66.                 * bit5-CYCLE                1-ENABLE                                                        0-DISABLE 周期采样ACC
  67.                 * bit4-GYRO_STANDBY                 1-GYRO_SLEEP          0-GYRO_NROMAL
  68.                 * bit3-TMEP_DIS        1-DISBALE TEMP                                0-ENABLE_TEMP
  69.                 * bit2:0-CLKSEL[2:0]        0or6-internal 20M  1~5-auto clk 7-no clk
  70.                 */
  71.         uc_icm20602_reg_config_value_p = 0x80;   //standby
  72.         HAL_I2C_Mem_Write(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_PWR_MGMT_1_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_config_value_p,        1,        100);
  73.         /*wait ICM20602 RESET completed*/
  74.         do
  75.         {
  76.                 HAL_I2C_Mem_Read(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_value_fdb_p, 1, 100);
  77.         }while(uc_icm20602_reg_value_fdb_p&0x80);
  78.         HAL_Delay(100);
  79.        
  80.         /*auto clk to achieve full gyroscope performance*/
  81.         uc_icm20602_reg_config_value_p = 0x01;   
  82.         HAL_I2C_Mem_Write(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_PWR_MGMT_1_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_config_value_p,        1,        100);

  83.         /**
  84.                 * ICM20602_CFG_REG_ADDR
  85.                 * bit6-FIFO MODE                                        1-FIFO满了不再填写                0-FIFO满了替换
  86.                 * bit5:3-EXT_SYNC_SET                        1~7-SYNC SOURCE                        0-DISABLE
  87.                 * bit2:0-DLPF_CFG[2:0]                DLPF截至频率配置
  88.                 */
  89.         uc_icm20602_reg_config_value_p = 0x00;   
  90.         HAL_I2C_Mem_Write(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_CFG_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_config_value_p,        1,        100);
  91.        
  92.         /**
  93.                 * ICM20602_GYRO_CFG_REG_ADDR
  94.                 * bit7-XG_ST                                                        X_GYRO self-test
  95.                 * bit6-YG_ST                                                        Y_GYRO self-test
  96.                 * bit5-ZG_ST                                                        Z_GYRO self-test
  97.                 * bit4:3-FS_SEL                                                00-±250dps        01-±500dps        10-±1000dps  11-±2000dps
  98.                 * bit1:0-FCHOICE_B                                1~3-DLPF DISBALE              0-DLPF ENABLE
  99.                 */
  100.         uc_icm20602_reg_config_value_p = 0x18;   
  101.         HAL_I2C_Mem_Write(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_GYRO_CFG_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_config_value_p,        1,        100);
  102.        
  103.         /*计算陀螺的分辨率*/
  104.         f_icm20602_gyro_scale = (1/131.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
  105.        
  106.         /**
  107.                 * ICM20602_ACC_CFG_REG_ADDR
  108.                 * bit7-XA_ST                                                        X_ACC self-test
  109.                 * bit6-YA_ST                                                        Y_ACC self-test
  110.                 * bit5-ZA_ST                                                        Z_ACC self-test
  111.                 * bit4:3-FS_SEL                                                00-±2g        01-±4g        10-±8g  11-±16g
  112.                 */
  113.         uc_icm20602_reg_config_value_p = 0x00;   
  114.         HAL_I2C_Mem_Write(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_CFG_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        &uc_icm20602_reg_config_value_p,        1,        100);
  115.        
  116.         /*计算陀螺的分辨率*/
  117.         f_icm20602_acc_scale = (1/16384.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
  118. }



  119. /**
  120.   * @brief         get icm20602 data
  121.         * @note                 不要再其他位置访问icm20602
  122.         *                                        角速度数据为float类型,存储在float *        p_f_icm20602_gyro_data_p (float        icm20602_gyro[3])
  123.   */

  124. void        Read_Icm20602_Data(I2C_HandleTypeDef *hi2c,        float *        p_f_icm20602_gyro_data_p,        float *p_f_icm20602_acc_data_p)
  125. {
  126.         static        FlagStatus        st_first_read_icm20602_reg_data_flag_p = SET;
  127.        
  128.         uint8_t                uc_icm20602_data_p[14];
  129.        
  130.         if(SET == st_first_read_icm20602_reg_data_flag_p)
  131.         {
  132.                 /*读取一次角度寄存器的值,使auto_increment pointer锁定在angle_reg,保证后续读取不需要发送内部寄存器地址*/
  133.                 HAL_I2C_Mem_Read(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_XOUT_H_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        uc_icm20602_data_p,        14,        100);       
  134.                 st_first_read_icm20602_reg_data_flag_p = RESET;
  135.         }
  136.         else
  137.         {
  138.                 HAL_I2C_Mem_Read(hi2c,        ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_XOUT_H_REG_ADDR,        I2C_MEMADD_SIZE_8BIT,        uc_icm20602_data_p,        14,        100);       
  139.         }
  140.        
  141.         p_f_icm20602_acc_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[0] <<8 )|uc_icm20602_data_p[1] )*f_icm20602_acc_scale;
  142.         p_f_icm20602_acc_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[2] <<8 )|uc_icm20602_data_p[3] )*f_icm20602_acc_scale;
  143.         p_f_icm20602_acc_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[4] <<8 )|uc_icm20602_data_p[5] )*f_icm20602_acc_scale;       
  144.        
  145.         p_f_icm20602_gyro_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[8] <<8 )|uc_icm20602_data_p[9] )*f_icm20602_gyro_scale;
  146.         p_f_icm20602_gyro_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[10] <<8 )|uc_icm20602_data_p[11] )*f_icm20602_gyro_scale;
  147.         p_f_icm20602_gyro_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[12] <<8 )|uc_icm20602_data_p[13] )*f_icm20602_gyro_scale;       
  148. }



  149. /*--------------------------------------------------模拟I2C读取Icm20602数据--------------------------------------*/
  150. /**
  151.   * @brief         init Icm20602               
  152.   */
  153. uint8_t        uc_icm20602_reg_value_fdb_p;
  154. void        Init_Icm20602_Soft(void)
  155. {
  156.         uint8_t        uc_icm20602_reg_config_value_p;
  157.        
  158.        
  159.         uc_icm20602_reg_value_fdb_p = I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_ID_REG_ADDRESS);
  160.        
  161.         /**
  162.                 * ICM20602_PWR_MGMT_1_REG_ADDR
  163.                 * bit7-RST                        1-trig device reset          0-no action
  164.                 * bit6-SLEEP                1-SLEEP                                                                0-NORMAL
  165.                 * bit5-CYCLE                1-ENABLE                                                        0-DISABLE 周期采样ACC
  166.                 * bit4-GYRO_STANDBY                 1-GYRO_SLEEP          0-GYRO_NROMAL
  167.                 * bit3-TMEP_DIS        1-DISBALE TEMP                                0-ENABLE_TEMP
  168.                 * bit2:0-CLKSEL[2:0]        0or6-internal 20M  1~5-auto clk 7-no clk
  169.                 */
  170.         uc_icm20602_reg_config_value_p = 0x80;   //standby
  171.         I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_PWR_MGMT_1_REG_ADDR, uc_icm20602_reg_config_value_p);
  172.         /*wait ICM20602 RESET completed*/
  173.         while(I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_PWR_MGMT_1_REG_ADDR)&0x80);
  174.         HAL_Delay(100);
  175.        
  176.         /*auto clk to achieve full gyroscope performance*/
  177.         uc_icm20602_reg_config_value_p = 0x01;   
  178.         I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_PWR_MGMT_1_REG_ADDR, uc_icm20602_reg_config_value_p);

  179.         /**
  180.                 * ICM20602_CFG_REG_ADDR
  181.                 * bit6-FIFO MODE                                        1-FIFO满了不再填写                0-FIFO满了替换
  182.                 * bit5:3-EXT_SYNC_SET                        1~7-SYNC SOURCE                        0-DISABLE
  183.                 * bit2:0-DLPF_CFG[2:0]                DLPF截至频率配置
  184.                 */
  185.         uc_icm20602_reg_config_value_p = 0x00;   
  186.         I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_CFG_REG_ADDR,        uc_icm20602_reg_config_value_p);
  187.        
  188.         /**
  189.                 * ICM20602_GYRO_CFG_REG_ADDR
  190.                 * bit7-XG_ST                                                        X_GYRO self-test
  191.                 * bit6-YG_ST                                                        Y_GYRO self-test
  192.                 * bit5-ZG_ST                                                        Z_GYRO self-test
  193.                 * bit4:3-FS_SEL                                                00-±250dps        01-±500dps        10-±1000dps  11-±2000dps
  194.                 * bit1:0-FCHOICE_B                                1~3-DLPF DISBALE              0-DLPF ENABLE
  195.                 */
  196.         uc_icm20602_reg_config_value_p = 0x18;   
  197.         I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_GYRO_CFG_REG_ADDR,        uc_icm20602_reg_config_value_p);
  198.        
  199.         uc_icm20602_reg_value_fdb_p = I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_GYRO_CFG_REG_ADDR);
  200.         /*计算陀螺的分辨率*/
  201.         f_icm20602_gyro_scale = (1/131.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
  202.        
  203.         /**
  204.                 * ICM20602_ACC_CFG_REG_ADDR
  205.                 * bit7-XA_ST                                                        X_ACC self-test
  206.                 * bit6-YA_ST                                                        Y_ACC self-test
  207.                 * bit5-ZA_ST                                                        Z_ACC self-test
  208.                 * bit4:3-FS_SEL                                                00-±2g        01-±4g        10-±8g  11-±16g
  209.                 */
  210.         uc_icm20602_reg_config_value_p = 0x00;   
  211.         I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_CFG_REG_ADDR,        uc_icm20602_reg_config_value_p);
  212.        
  213.         /*计算陀螺的分辨率*/
  214.         f_icm20602_acc_scale = (1/16384.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
  215. }



  216. /**
  217.   * @brief         get icm20602 data
  218.         * @note                 不要再其他位置访问icm20602
  219.         *                                        角速度数据为float类型,存储在float *        p_f_icm20602_gyro_data_p (float        icm20602_gyro[3])
  220.   */
  221. uint8_t                uc_icm20602_data_p[14];  
  222. float                        f_icm20602_temp = 0;
  223. void        Read_Icm20602_Data_Soft(float *        p_f_icm20602_gyro_data_p,        float *p_f_icm20602_acc_data_p)
  224. {
  225.         static        FlagStatus        st_first_read_icm20602_reg_data_flag_p = SET;
  226.        
  227.        
  228.        
  229.         if(SET == st_first_read_icm20602_reg_data_flag_p)
  230.         {
  231.                 /*读取一次角度寄存器的值,使auto_increment pointer锁定在angle_reg,保证后续读取不需要发送内部寄存器地址*/
  232.                 I2C_Read_Multi_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_XOUT_H_REG_ADDR,        uc_icm20602_data_p,        14);       
  233.                 st_first_read_icm20602_reg_data_flag_p = RESET;
  234.         }
  235.         else
  236.         {
  237.                 I2C_Read_Multi_Reg(ICM20602_DEVICE_ADDRESS,        ICM20602_ACC_XOUT_H_REG_ADDR,        uc_icm20602_data_p,        14);       
  238.         }
  239.        
  240.         p_f_icm20602_acc_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[0] <<8 )|uc_icm20602_data_p[1] )*f_icm20602_acc_scale;
  241.         p_f_icm20602_acc_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[2] <<8 )|uc_icm20602_data_p[3] )*f_icm20602_acc_scale;
  242.         p_f_icm20602_acc_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[4] <<8 )|uc_icm20602_data_p[5] )*f_icm20602_acc_scale;       
  243.        
  244.         p_f_icm20602_gyro_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[8] <<8 )|uc_icm20602_data_p[9] )*f_icm20602_gyro_scale;
  245.         p_f_icm20602_gyro_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[10] <<8 )|uc_icm20602_data_p[11] )*f_icm20602_gyro_scale;
  246.         p_f_icm20602_gyro_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[12] <<8 )|uc_icm20602_data_p[13] )*f_icm20602_gyro_scale;       

  247.         f_icm20602_temp = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[6] <<8 )|uc_icm20602_data_p[7] )/326.8 + 25;
  248. }
  249. /**
  250.   ******************************************************************************
  251.   * File Name          : icm20602_driver.h
  252.   * Description        : This file provides code for the icm20602 .
  253.   ******************************************************************************
  254.   *
  255.   * COPYRIGHT(c) 2016 aibird
  256.   *
  257.   ******************************************************************************
  258.         *
  259.         * Author:
  260.         *
  261.         ******************************************************************************
  262.         */

  263. /* Define to prevent recursive inclusion -------------------------------------*/
  264. #ifndef        _ICM20602_DRIVER_H
  265. #define        _ICM20602_DRIVER_H

  266. #ifdef __cplusplus
  267. extern "C" {
  268. #endif

  269. /* Includes ------------------------------------------------------------------*/
  270. #include "stm32f1xx_hal.h"


  271. void        Init_Icm20602(I2C_HandleTypeDef *hi2c);
  272. void        Read_Icm20602_Data(I2C_HandleTypeDef *hi2c,        float *        p_f_icm20602_gyro_data_p,        float *p_f_icm20602_acc_data_p);

  273. void        Init_Icm20602_Soft(void);
  274. void        Read_Icm20602_Data_Soft(float *        p_f_icm20602_gyro_data_p,        float *p_f_icm20602_acc_data_p);         




  275. #ifdef __cplusplus
  276. }
  277. #endif         
  278.          
  279. #endif         


ICM20602.JPG
smilingangel 发表于 2017-12-13 23:23 | 显示全部楼层
这些资料的先下载先来的看看的
lgl63167048 发表于 2017-12-26 17:18 | 显示全部楼层
smilingangel 发表于 2017-12-13 23:23
这些资料的先下载先来的看看的

支持
lgl63167048 发表于 2017-12-26 17:18 | 显示全部楼层
evanlee1025 发表于 2018-11-16 15:03 | 显示全部楼层
楼主目前还在做这方面吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

189

主题

897

帖子

12

粉丝
快速回复 在线客服 返回列表 返回顶部