TI CC265x的IIC通讯读取IMU BMI08x数据

2023-05-16

SmartLink CC265x是TI公司出的无线MCU平台器件。最近玩了个小项目用TI的CC265x平板IIC接口通讯,获取博世BMI08x陀螺仪、加速度计传感器的数据。本篇博客亦是对博客《树莓派IIC通讯获取BMI08x IMU数据进行姿态解算,并通过UART/TCP在rviz上显示》的一个扩展。

目录

1. CCS(Code Composer Studio)的安装

2. IIC模块的配置与调试


1. CCS(Code Composer Studio)的安装

CCS的针对TI开发板的编程与下载工具,最新软件可在CCSTUDIO IDE、配置、编译器或调试器 | TI.com.cn下载,其使用手册可以在Code Composer Studio User’s Guide — Code Composer Studio 11.0.0 Documentation中查看。

大多数情况下我们是使用安装好之后的官方自带例程,并再其基础上更新。

 比如我们想要了解I2C相关的例程,直接选择后import导入到本地路径。

关于如何从零建立自己的CCS工程,暂时还没研究清楚,有大神清楚还望多多指教,万分感谢。

2. IIC模块的配置与调试

我开发的TI板是CC2652,9,10号引脚为I2C的通讯线。

这些引脚的定义需结合syscfg,比如Display表示可通过开发板的串口将数据打印出来,TI的库已经封装好了这一层。

另外还可以配置一些GPIO用于LED灯的操作。

官方的给的IIC例程写得有点让人难理解,全都封装在I2C_Transaction函数了,在读寄存器处并没有说明要写入寄存器地址。

 *  // Import I2C Driver definitions
 *  #include <ti/drivers/I2C.h>
 *
 *  // Define name for an index of an I2C bus
 *  #define SENSORS 0
 *
 *  // Define the slave address of device on the SENSORS bus
 *  #define OPT_ADDR 0x47
 *
 *  // One-time init of I2C driver
 *  I2C_init();
 *
 *  // initialize optional I2C bus parameters
 *  I2C_Params params;
 *  I2C_Params_init(&params);
 *  params.bitRate = I2C_400kHz;
 *
 *  // Open I2C bus for usage
 *  I2C_Handle i2cHandle = I2C_open(SENSORS, &params);
 *
 *  // Initialize slave address of transaction
 *  I2C_Transaction transaction = {0};
 *  transaction.slaveAddress = OPT_ADDR;
 *
 *  // Read from I2C slave device
 *  transaction.readBuf = data;
 *  transaction.readCount = sizeof(data);
 *  transaction.writeCount = 0;
 *  I2C_transfer(i2cHandle, &transaction);
 *
 *  // Write to I2C slave device
 *  transaction.writeBuf = command;
 *  transaction.writeCount = sizeof(command);
 *  transaction.readCount = 0;
 *  I2C_transferTimeout(i2cHandle, &transaction, 5000);
 *
 *  // Close I2C
 *  I2C_close(i2cHandle);
 *  @endcode
 *
 *  @anchor ti_drivers_I2C_Examples
 *  ## Examples
 *
 *  @li @ref ti_drivers_I2C_Example_open "Getting an I2C bus handle"
 *  @li @ref ti_drivers_I2C_Example_write3bytes "Sending 3 bytes"
 *  @li @ref ti_drivers_I2C_Example_read5bytes "Reading 5 bytes"
 *  @li @ref ti_drivers_I2C_Example_writeread "Writing then reading in a single transaction"
 *  @li @ref ti_drivers_I2C_Example_callback "Using Callback mode"
 *
 *  @anchor ti_drivers_I2C_Example_open
 *  ## Opening the I2C Driver
 *
 *  After calling I2C_init(), the application can open an I2C instance by
 *  calling I2C_open().The following code example opens an I2C instance with
 *  default parameters by passing @p NULL for the #I2C_Params argument.
 *
 *  @code
 *  I2C_Handle i2cHandle;
 *
 *  i2cHandle = I2C_open(0, NULL);
 *
 *  if (i2cHandle == NULL) {
 *      // Error opening I2C
 *      while (1) {}
 *  }
 *  @endcode
 *
 *  @anchor ti_drivers_I2C_Example_write3bytes
 *  ## Sending three bytes of data.
 *
 *  @code
 *  I2C_Transaction i2cTransaction = {0};
 *  uint8_t writeBuffer[3];
 *
 *  writeBuffer[0] = 0xAB;
 *  writeBuffer[1] = 0xCD;
 *  writeBuffer[2] = 0xEF;
 *
 *  i2cTransaction.slaveAddress = 0x50;
 *  i2cTransaction.writeBuf = writeBuffer;
 *  i2cTransaction.writeCount = 3;
 *  i2cTransaction.readBuf = NULL;
 *  i2cTransaction.readCount = 0;
 *
 *  status = I2C_transfer(i2cHandle, &i2cTransaction);
 *
 *  if (status == false) {
 *      // Unsuccessful I2C transfer
 *      if (i2cTransaction.status == I2C_STATUS_ADDR_NACK) {
 *          // I2C slave address not acknowledged
 *      }
 *  }
 *  @endcode
 *
 *  @anchor ti_drivers_I2C_Example_read5bytes
 *  ## Reading five bytes of data.
 *
 *  @code
 *  I2C_Transaction i2cTransaction = {0};
 *  uint8_t readBuffer[5];
 *
 *  i2cTransaction.slaveAddress = 0x50;
 *  i2cTransaction.writeBuf = NULL;
 *  i2cTransaction.writeCount = 0;
 *  i2cTransaction.readBuf = readBuffer;
 *  i2cTransaction.readCount = 5;
 *
 *  status = I2C_transfer(i2cHandle, &i2cTransaction);
 *
 *  if (status == false) {
 *      if (i2cTransaction.status == I2C_STATUS_ADDR_NACK) {
 *          // I2C slave address not acknowledged
 *      }
 *  }
 *  @endcode
 *
 *  @anchor ti_drivers_I2C_Example_writeread
 *  ## Writing two bytes and reading four bytes in a single transaction.
 *
 *  @code
 *  I2C_Transaction i2cTransaction = {0};
 *  uint8_t readBuffer[4];
 *  uint8_t writeBuffer[2];
 *
 *  writeBuffer[0] = 0xAB;
 *  writeBuffer[1] = 0xCD;
 *
 *  i2cTransaction.slaveAddress = 0x50;
 *  i2cTransaction.writeBuf = writeBuffer;
 *  i2cTransaction.writeCount = 2;
 *  i2cTransaction.readBuf = readBuffer;
 *  i2cTransaction.readCount = 4;
 *
 *  status = I2C_transfer(i2cHandle, &i2cTransaction);
 *
 *  if (status == false) {
*       if (i2cTransaction->status == I2C_STATUS_ADDR_NACK) {
*           // slave address not acknowledged
*       }
 *  }
 *  @endcode

感谢 获夜 的博文《CC2652RB硬件I2C读取FXOS8700CQ加速度传感器》 及其给与的帮助,让我对TI CCS使用IIC库有所理解。这里依旧使用博世官方提供的API  “https://github.com/BoschSensortec/BMI08x-Sensor-API”,对common函数的读写操作进行了改进(而不是使用博世提供的COINES平台)。

更改为TI获取IIC的读写寄存器操作如下:

/*!
 * I2C read function map to SimpleLink launchpad
 */
int8_t bmi08x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
    uint8_t dev_addr = *(uint8_t*)intf_ptr;

    /* Common I2C transaction setup */
    i2cTransaction.slaveAddress = dev_addr;
    i2cTransaction.writeBuf   = &reg_addr;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf    = reg_data;
    i2cTransaction.readCount  = len;

    uint8_t cnt = 0;
    if (I2C_transfer(i2c_handle, &i2cTransaction)) {
        for(cnt = 0; cnt < len; cnt++)
            Display_printf(display, 0, 0, "Device 0x%x read register 0x%x value = 0x%x", dev_addr, reg_addr+cnt, reg_data[cnt]);
    }
    else {
        i2cErrorHandler(&i2cTransaction, display);
        return -2;
    }

    return 0;
}

/*!
 * I2C write function map to SimpleLink launchpad
 */
int8_t bmi08x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
    uint8_t dev_addr = *(uint8_t*)intf_ptr;
    i2cTransaction.slaveAddress = dev_addr;

    uint8_t cnt = 0;
    for(cnt = 0; cnt < len; cnt++)
    {
        uint8_t writeBuf[2] = {0};
        writeBuf[0] = reg_addr+cnt;
        writeBuf[1] = reg_data[cnt];
        /* Common I2C transaction setup */
        i2cTransaction.writeBuf   = writeBuf;
        i2cTransaction.writeCount = 2;
        i2cTransaction.readBuf    = NULL;
        i2cTransaction.readCount  = 0;
        if (I2C_transfer(i2c_handle, &i2cTransaction)) {
            Display_printf(display, 0, 0, "Device 0x%x write register 0x%x value = 0x%x", dev_addr, reg_addr + cnt, reg_data[cnt]);
        }
        else {
            i2cErrorHandler(&i2cTransaction, display);
            return -2;
        }
    }

    return 0;
}

/*
 *  ======== i2cErrorHandler ========
 */
void i2cErrorHandler(I2C_Transaction *transaction, Display_Handle display)
{
    switch (transaction->status) {
    case I2C_STATUS_TIMEOUT:
        Display_printf(display, 0, 0, "I2C transaction timed out!");
        break;
    case I2C_STATUS_CLOCK_TIMEOUT:
        Display_printf(display, 0, 0, "I2C serial clock line timed out!");
        break;
    case I2C_STATUS_ADDR_NACK:
        Display_printf(display, 0, 0, "I2C slave address 0x%x not"
            " acknowledged!", transaction->slaveAddress);
        break;
    case I2C_STATUS_DATA_NACK:
        Display_printf(display, 0, 0, "I2C data byte not acknowledged!");
        break;
    case I2C_STATUS_ARB_LOST:
        Display_printf(display, 0, 0, "I2C arbitration to another master!");
        break;
    case I2C_STATUS_INCOMPLETE:
        Display_printf(display, 0, 0, "I2C transaction returned before completion!");
        break;
    case I2C_STATUS_BUS_BUSY:
        Display_printf(display, 0, 0, "I2C bus is already in use!");
        break;
    case I2C_STATUS_CANCEL:
        Display_printf(display, 0, 0, "I2C transaction cancelled!");
        break;
    case I2C_STATUS_INVALID_TRANS:
        Display_printf(display, 0, 0, "I2C transaction invalid!");
        break;
    case I2C_STATUS_ERROR:
        Display_printf(display, 0, 0, "I2C generic error!");
        break;
    default:
        Display_printf(display, 0, 0, "I2C undefined error case!");
        break;
    }
}

而这两个读写IIC寄存器恰好是获取IMU数据的关键。在IIC线程获取到数据后我们可以通过Display_printf函数将其打印出来。这样通过串口助手便将数据显示出来了,如下。

 

Enjoy!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TI CC265x的IIC通讯读取IMU BMI08x数据 的相关文章

  • DHT12温湿度传感器IIC,I2C接口调试心得和代码说明

    来源 xff1a http www fuhome net bbs forum php mod 61 viewthread amp tid 61 2141 DHT11那个单总线的温湿度传感器用的很多了 xff0c aosong推出了DHT12
  • Ubuntu18下xsens IMU的驱动安装及使用imu_utils标定

    最近在做xsens IMU的标定工作 xff0c 网上资源很多很杂 xff0c 打算按自己的操作过程 细节及遇到的问题记录一下 xff0c 里面有参考的博文都附了链接 主体可参考此博文 xff1a VIO 中 IMU 的标定流程 1 3 i
  • 关于imu的介绍

    1 imu时惯性运动丹云 xff0c 包含加速度计和陀螺传感器的组合 它被用来检查加速度和角速度 xff08 IMU传感器 xff0c 你所需要知道的全部 知乎 xff09 虽然时外文翻译的 xff0c 凡是整体风格清晰 2 imu的使用
  • MAG02 IMU传感器模块替代MPU6050模块介绍

    MAG02模块内置TDK高精度6轴IMU 惯性测量单元 xff09 传感器芯片 xff0c 通过处理器读取传感器数据 xff0c 并经过内部复杂运算后通过串口输出加速度 xff0c 角速度 xff0c 角度等数据 xff0c 大大减轻了用户
  • 飞控IMU数据进阶处理(FFT,滤波器)

    前面的文章 xff08 知乎专栏 https zhuanlan zhihu com c 60591778 xff09 曾简单讲过IMU数据 xff08 陀螺仪 加速度数据 xff09 的校准以及一阶低通滤波 本文在此基础上更进一步讲一下数据
  • 无人车传感器 IMU与GPS数据融合进行定位机制

    前言 上一次的分享里 xff0c 我介绍了GPS的原理 xff08 三角定位 xff09 及特性 xff08 精度 频率 xff09 xff0c 同时也从无人车控制的角度 xff0c 讨论了为什么仅有GPS无法满足无人车的定位要求 为了能让
  • RealSenseD345I —— imu + camera标定

    目录 1 标定目的 2 标定准备 3 标定步骤 nbsp nbsp nbsp nbsp 1 IMU标定 nbsp nbsp nbsp
  • loam中imu消除重力加速度的数学推导

    最近在看loam的源码发现里面有一段关于imu消除重力加速度的源码 xff0c 刚开始看不明白后来终于搞清楚了 xff0c 欢迎大家批评指正 要理解这个问题首先得明白欧拉角到旋转矩阵的变换 先上图 此图描述的是先绕X xff0c 再绕Y x
  • spi,iic,uart,pcie区别

    一 spi SPI 是英语Serial Peripheral interface的缩写 xff0c 顾名思义就是串行外围设备接口 xff0c 是同步传输协议 xff0c 特征是 xff1a 设备有主机 xff08 master xff09
  • IMU让无人机控制变得更轻松

    多翼无人机广泛应用于监视和侦察 航空摄影和测量 搜索和救援任务 通信中继和环境监测 目前无人机的手动控制大部分基于视觉反馈 xff0c 所以操作环境中的障碍物会造成干扰 因此 xff0c 需要其他感官反馈 xff0c 例如触觉 xff0c
  • STM32软件模拟iic驱动oled(显示汉字,图片)(一)

    一 iic驱动模式 1 硬件驱动 xff1a 所谓硬件驱动就是使用STM32板子上固定的iic接口 xff0c 但是由于板载iic数量有限 xff0c 且大多和别的外设有引脚复用 xff0c 在别的外设使用的情况下还得通过重映射引到别的引脚
  • UART、IIC、SPI、CAN通信的区别与应用

    文章目录 1 通信的基本知识1 1 数据通信的种类1 1 1 串行通信1 1 2 并行通信1 1 3 总结 1 2 数据通信的传输方向1 2 1 单工1 2 2 半双工1 2 3 全双工1 2 4 总结 1 3 数据通信的方式1 3 1 同
  • IMU误差模型简介及VINS使用说明

    1 IMU误差来源 2 IMU噪声模型 Noise and Bias kalibr中的imu noise model 参考 xff1a https github com ethz asl kalibr wiki IMU Noise Mode
  • realsense d435i标定imu与camera

    realsense d435i标定imu与camera 1 标定目的 realsense d435i包含两个红外相机 红外发射器 RGB相机和IMU四个模块 xff0c 显然四个传感器的空间位置是不同的 xff0c 我们在处理图像和IMU数
  • IIC的通信波形分析

    关于IIC xff0c 不解释它的历史了 xff0c 有兴趣自己去百度看看 xff0c 本文的图片是由周立功的LAB6021逻辑分析仪抓取的 xff0c 通信的波形是抓取的cypress的psoc 4000芯片得到的 最近项目需要用到触摸I
  • 武汉大学研究生组合导航课程合集【2022年春】

    第四公式中kk是权重 zk hx 为innovation新息 即真实的观测 估计的观测 前者包含观测误差 gps的电离层 多径 后者包含估计误差 kk近似1 则无限相信新观测 kk 0 相信估计
  • 浙江大学提出自感知IMU网络精准捕获3D变形

    运动捕捉目前有两种主流方法 视觉捕捉能捕获复杂的三维几何变形 但依赖于昂贵的光学设备并且存在视线遮挡问题 基于IMU的方法虽然简便 但难以捕获细微的3D变形 为了解决这个问题 浙江大学的研究者们提出了一种可配置的自感知IMU传感器网络 解决
  • I2C与SPI通信总线协议

    仅以寄存器地址为8Bit的器件为例 例如MPU6500 LSM6DS3 I2C通信协议 I2C 的要点是了解I2C通信帧的组成部分 START起始位 STOP停止位 ACK NACK信号 从机器件地址 从机寄存器地址 I2C读的时序比较繁琐
  • 四元素与旋转矩阵

    如何描述三维空间中刚体的旋转 是个有趣的问题 具体地说 就是刚体上的任意一个点P x y z 围绕过原点的轴 i j k 旋转 求旋转后的点P x y z 旋转矩阵 旋转矩阵乘以点P的齐次坐标 得到旋转后的点P 因此旋转矩阵可以描述旋转 x
  • IMU用于上肢功能评估

    来自日本团队牵头研究揭示了利用九轴运动传感器评估上肢Fugl Meyer FMA 的潜力 该探索侧重于将惯性测量单元 IMU 集成到 FMA 的方法中 并探究是否可以出现标准化和更客观的测量 从而解决动态运动评估中的一个紧迫问题 九轴 IM

随机推荐