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

【STEVAL-STWINKT1B】:07读取IIS2DH数据

[复制链接]
〃聪聪哥哥 发布时间:2026-3-30 17:25

一:IIS2DH芯片描述

IIS2DH是一款超低功耗高性能三轴线性加速度计,具有数字I2C/SPI串行接口标准输出。

IIS2DH具有用户可选的满量程:+2g/+4g/+8g/+16g,能够以1Hz至5.3kHz的输出数据速率测量加速度。

该设备可配置为通过两个独立的惯性唤醒自由落体事件以及设备自身的位置来生成中断信号。

自检功能允许用户在最终应用中检查传感器的功能。

IIS2DH采用小型薄型塑料焊盘网格阵列封装(LGA),并保证可在-40°C至+85°C的宽温度范围内工作。

二:软件代码

  stmdev_ctx_t dev_ctx;
  dev_ctx.write_reg = platform_write;
  dev_ctx.read_reg = platform_read;
//  dev_ctx.mdelay = platform_delay;
  dev_ctx.handle = &SENSOR_BUS;
  /* Initialize platform specific hardware */
  platform_init();
  /* Wait sensor boot time */
  platform_delay(BOOT_TIME);
  /* Check device ID */
  iis2dh_device_id_get(&dev_ctx, &whoamI);

  if (whoamI != IIS2DH_ID) {
    while (1) {
      /* manage here device not found */
    }
  }

  /* Enable Block Data Update */
  iis2dh_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
  /* Set Output Data Rate to 1Hz */
  iis2dh_data_rate_set(&dev_ctx, IIS2DH_ODR_1Hz);
  /* Set full scale to 2g */
  iis2dh_full_scale_set(&dev_ctx, IIS2DH_2g);
  /* Enable temperature sensor */
  iis2dh_temperature_meas_set(&dev_ctx, IIS2DH_TEMP_ENABLE);
  /* Set device in continuous mode with 12 bit resol. */
  iis2dh_operating_mode_set(&dev_ctx, IIS2DH_HR_12bit);

2.2 读取数据函数

    iis2dh_reg_t reg;
    /* Read output only if new value available */
    iis2dh_xl_data_ready_get(&dev_ctx, &reg.byte);

    if (reg.byte) {
      /* Read accelerometer data */
      memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
      iis2dh_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
      acceleration_mg[0] =
        iis2dh_from_fs2_hr_to_mg(data_raw_acceleration[0]);
      acceleration_mg[1] =
        iis2dh_from_fs2_hr_to_mg(data_raw_acceleration[1]);
      acceleration_mg[2] =
        iis2dh_from_fs2_hr_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));
    }

    iis2dh_temp_data_ready_get(&dev_ctx, &reg.byte);

    if (reg.byte) {
      /* Read temperature data */
      memset(&data_raw_temperature, 0x00, sizeof(int16_t));
      iis2dh_temperature_raw_get(&dev_ctx, &data_raw_temperature);
      temperature_degC =
        iis2dh_from_lsb_hr_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-5.png

收藏 评论0 发布时间:2026-3-30 17:25

举报

0个回答

所属标签

相似分享

官网相关资源

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