你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STEVAL-STWINKT1B】:09读取ISM330DHCX数据

[复制链接]
〃聪聪哥哥 发布时间:2026-3-31 07:59

一:ISM330DHCX知识分享:

带可选满量程的3D加速度计:+2/+4/+8/+16g

带扩展可选满量程的3D陀螺仪:+125/±250/±500/±1000/±2000/±4000 dps

扩展温度范围从-40到+105°C嵌入式补偿,确保温度变化下的高稳定性

SPI/I2C串行接口

辅助SPI串行接口,用于陀螺仪和加速度计的数据输出(OIS及其他稳定应用)

六通道同步输出

传感器集线器功能,可高效从额外外部传感器收集数据;

嵌入式智能FIFO,最大支持9千字节

可编程有限状态机,用于处理加速度计、陀螺仪和外部传感器的数据

机器学**智能嵌入式功能与中断:倾斜检测、自由落体、唤醒、6D/4D方向、单击与双击

嵌入式计步器、步数检测器和计数器,用于医疗保健应用

模拟供电电压:1.71V至3.6V

嵌入式温度传感器陀螺仪和加速度计均内置自检功能高抗冲击性

符合ECOPACK、RoHS和“绿色”标准

二:代码:

2.1 初始化

 stmdev_ctx_t dev_ctx;
  /* Initialize mems driver interface */
  dev_ctx.write_reg = platform_write;
  dev_ctx.read_reg = platform_read;
  dev_ctx.mdelay = platform_delay;
  dev_ctx.handle = &hspi3;
  /* Init test platform */
  platform_init();
  /* Wait sensor boot time */
  platform_delay(BOOT_TIME);
  /* Check device ID */
  ism330dhcx_device_id_get(&dev_ctx, &whoamI);

  if (whoamI != ISM330DHCX_ID)
    while (1);

  /* Restore default configuration */
  ism330dhcx_reset_set(&dev_ctx, PROPERTY_ENABLE);

  do {
    ism330dhcx_reset_get(&dev_ctx, &rst);
  } while (rst);

  /* Start device configuration. */
  ism330dhcx_device_conf_set(&dev_ctx, PROPERTY_ENABLE);
  /* Enable Block Data Update */
  ism330dhcx_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
  /* Set Output Data Rate */
  ism330dhcx_xl_data_rate_set(&dev_ctx, ISM330DHCX_XL_ODR_12Hz5);
  ism330dhcx_gy_data_rate_set(&dev_ctx, ISM330DHCX_GY_ODR_12Hz5);
  /* Set full scale */
  ism330dhcx_xl_full_scale_set(&dev_ctx, ISM330DHCX_2g);
  ism330dhcx_gy_full_scale_set(&dev_ctx, ISM330DHCX_2000dps);
  /* Configure filtering chain(No aux interface)
   *
   * Accelerometer - LPF1 + LPF2 path
   */
  ism330dhcx_xl_hp_path_on_out_set(&dev_ctx, ISM330DHCX_LP_ODR_DIV_100);
  ism330dhcx_xl_filter_lp2_set(&dev_ctx, PROPERTY_ENABLE);

2.2 数据读取

    uint8_t reg;
    /* Read output only if new xl value is available */
    ism330dhcx_xl_flag_data_ready_get(&dev_ctx, &reg);

                        HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_0);
                HAL_Delay(500);
    if (reg) {
      /* Read acceleration field data */
      memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
      ism330dhcx_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
      acceleration_mg[0] =
        ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[0]);
      acceleration_mg[1] =
        ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[1]);
      acceleration_mg[2] =
        ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[2]);
      snprintf((char *)tx_buffer, sizeof(tx_buffer),
              "Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n",
              acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
      tx_com(tx_buffer, strlen((char const *)tx_buffer));
    }
                HAL_Delay(500);
    ism330dhcx_gy_flag_data_ready_get(&dev_ctx, &reg);

    if (reg) {
      /* Read angular rate field data */
      memset(data_raw_angular_rate, 0x00, 3 * sizeof(int16_t));
      ism330dhcx_angular_rate_raw_get(&dev_ctx, data_raw_angular_rate);
      angular_rate_mdps[0] =
        ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[0]);
      angular_rate_mdps[1] =
        ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[1]);
      angular_rate_mdps[2] =
        ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[2]);
      snprintf((char *)tx_buffer, sizeof(tx_buffer),
              "Angular rate [mdps]:%4.2f\t%4.2f\t%4.2f\r\n",
              angular_rate_mdps[0], angular_rate_mdps[1], angular_rate_mdps[2]);
      tx_com(tx_buffer, strlen((char const *)tx_buffer));
    }

    ism330dhcx_temp_flag_data_ready_get(&dev_ctx, &reg);
                HAL_Delay(500);
    if (reg) {
      /* Read temperature data */
      memset(&data_raw_temperature, 0x00, sizeof(int16_t));
      ism330dhcx_temperature_raw_get(&dev_ctx, &data_raw_temperature);
      temperature_degC = ism330dhcx_from_lsb_to_celsius(
                           data_raw_temperature);
      snprintf((char *)tx_buffer, sizeof(tx_buffer),
              "Temperature [degC]:%6.2f\r\n", temperature_degC);
      tx_com(tx_buffer, strlen((char const *)tx_buffer));
    }

三:实物验证:

03-7.png

收藏 评论0 发布时间:2026-3-31 07:59

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版