最常见的IMU:MPU6050

news/2024/5/21 16:49:31/文章来源:https://blog.csdn.net/wsl_longwudi/article/details/127214480

I2CI^2CI2C通讯

I2CI^2CI2C is a two-wire interface comprised of the signals serial data (SDA) and serial clock (SCL). In general, the lines are open-drain and bi-directional. In a generalized I-C interface implementation, attached devices can be a master or a slave. The master device puts the slave address on the bus, and the slave device with the matching address acknowledges the master.
​ The MPU-60X0 always operates as a slave device when communicating to the system processor, which thus acts as the master. SDA and SCL lines typically need pull-up resistors to VDD. The maximum bus speed is 400 kHz.
​ The slave address of the MPU-60X0 is b110100X(104 or 105) which is 7 bits long. The LSB bit of the 7 bit address is determined by the logic level on pin AD0. This allows two MPU-60X0s to be connected to the same IC bus. When used in this configuration, the address of the one of the devices should be b1101000 (pin AD0 is logic low) and the address of the other should be b1101001 (pin AD0 is logic high).

I2CI^2CI2C Communications Protocol

Communication on the I2CI^2CI2C bus starts when the master puts the START condition (S) on the bus, which is defined as a HIGH-to-LOW transition of the SDA line while SCL line is HIGH (see figure below). The bus is considered to be busy until the master puts a STOP condition § on the bus, which is defined as a LOW-to-HIGH transition on the SDA line while SCL is HIGH (see figure below).

Additionally, the bus remains busy if a repeated START (Sr) is generated instead of a STOP condition.

请添加图片描述

I2C data bytes are defined to be 8-bits long. There is no restriction to the number of bytes transmitted per data transfer. Each byte transferred must be followed by an acknowledge (ACK) signal. The clock for the acknowledge signal is generated by the master, while the receiver generates the actual acknowledge signal by pulling down SDA and holding it low during the HIGH portion of the acknowledge clock pulse.

If a slave is busy and cannot transmit or receive another byte of data until some other task has been
performed, it can hold SCL LOW, thus forcing the master into a wait state. Normal data transfer resumes when the slave is ready, and releases the clock line (refer to the following figure).

请添加图片描述

Communications
After beginning communications with the START condition (S), the master sends a 7-bit slave address
followed by an 8th8^{th}8th bit, the read/write bit. The read/write bit indicates whether the master is receiving data from or is writing to the slave device. Then, the master releases the SDA line and waits for the acknowledge signal (ACK) from the slave device. Each byte transferred must be followed by an acknowledge bit. To acknowledge, the slave device pulls the SDA line LOW and keeps it LOW for the high period of the SCL line.
Data transmission is always terminated by the master with a STOP condition §, thus freeing the
communications line. However, the master can generate a repeated START condition (Sr), and address
another slave without first generating a STOP condition §. A LOW to HIGH transition on the SDA line while SCL is HIGH defines the stop condition. AlI SDA changes should take place when SCL is low, with the exception of start and stop conditions.

在这里插入图片描述

To write the internal MPU-60X0 registers, the master transmits the start condition (S), followed by the I2CI^2CI2C address and the write bit (0). At the 9th9^{th}9th clock cycle (when the clock is high), the MPU-60X0 acknowledges the transfer. Then the master puts the register address (RA) on the bus. After the MPU-60X0 acknowledges the reception of the register address, the master puts the register data onto the bus. This is followed by the ACK signal, and data transfer may be concluded by the stop condition §. To write multiple bytes after the last ACK signal, the master can continue outputting data rather than transmitting a stop signal. In this case, the MPU-60X0 automatically increments the register address and loads the data to the appropriate register. The following figures show single and two-byte write sequences.

在这里插入图片描述

To read the internal MPU-60X0 registers, the master sends a start condition, followed by the I2CI^2CI2C address and a write bit(0), and then the register address that is going to be read. Upon receiving the ACK signal from the MPU-60X0, the master transmits a start signal followed by the slave address and read bit(1). As a result, the MPU-60X0 sends an ACK signal and the data. The communication ends with a not acknowledge (NACK) signal and a stop bit from master. The NACK condition is defined such that the SDA line remains high at the 9th9^{th}9th clock cycle. The following figures show single and two-byte read sequences.

在这里插入图片描述

在这里插入图片描述

除了开始位(Start)和停止位(stop),所有SDA的信号变化都必须在SCL的低电平完成。

从设备应答使用低电平(ACK),主设备应答采用高电平(NACK)

时钟SCL的上升沿作为读取的时刻,时钟SCL的下降沿作为发送的时刻

寄存器

  • 0x3B,加速度计的X轴分量ACC_X
  • 0x3D,加速度计的Y轴分量ACC_Y
  • 0x3F,加速度计的Z轴分量ACC_Z
  • 0x41,当前温度TEMP
  • 0x43,绕X轴旋转的角速度GYR_X
  • 0x45,绕Y轴旋转的角速度GYR_Y
  • 0x47,绕Z轴旋转的角速度GYR_Z

加速度计的三轴分量ACC_X、ACC_Y和ACC_Z均为16位有符号整数,分别表示器件在三个轴向上的加速度,取负值时加速度沿座标轴负向,取正值时沿正向。

配置寄存器

加速度配置寄存器

三个加速度分量均以重力加速度g的倍数为单位,能够表示的加速度范围,即倍率可以统一设定,有4个可选倍率:2g、4g、8g、16g。以ACC_X为例,若倍率设定为2g(默认),则意味着ACC_X取最小值-32768时,当前加速度为沿X轴正方向2倍的重力加速度;若设定为4g,取-32768时表示沿X轴正方向4倍的重力加速度,以此类推。显然,倍率越低精度越好,倍率越高表示的范围越大,这要根据具体的应用来设定

Register (Hex)Register (Decimal)Bit7Bit6Bit5Bit4Bit3Bit2Bit1Bit0
1C28XA_STYA_STZA_STAFS_SEL[1]AFS_SEL[1]

Parameters:

  • XA_ST: When set to 1, the X- Axis accelerometer performs self test.
  • YA_ST: When set to 1, the Y- Axis accelerometer performs self test.
  • ZA_ST: When set to 1, the Z- Axis accelerometer performs self test.
  • AFS_SEL: 2-bit unsigned value. Selects the full scale range of accelerometers
AFS_SELFull Scale Range
0± 2g
1± 4g
2± 8g
3± 16g
Wire.beginTransmission(0x68); //开启MPU-6050的传输
Wire.write(0x1C); //加速度倍率寄存器的地址
Wire.requestFrom(0x68, 1, true); //先读出原配置
unsigned char acc_conf = Wire.read();
acc_conf = ((acc_conf & 0xE7) | (f << 3));
Wire.write(acc_conf)
Wire.endTransmission(true); //结束传输,true表示释放总线

陀螺仪配置寄存器

绕X、Y和Z三个座标轴旋转的角速度分量GYR_X、GYR_Y和GYR_Z均为16位有符号整数。从原点向旋转轴方向看去,取正值时为顺时针旋转,取负值时为逆时针旋转。

三个角速度分量均以“度/秒”为单位,能够表示的角速度范围,即倍率可统一设定,有4个可选倍率:250度/秒、500度/秒、1000度/秒、2000度/秒。以GYR_X为例,若倍率设定为250度/秒,则意味着GYR取正最大值32768时,当前角速度为顺时针250度/秒;若设定为500度/秒,取32768时表示当前角速度为顺时针500度/秒。显然,倍率越低精度越好,倍率越高表示的范围越大。

以GYR_X为例,若当前设定的角速度倍率为1000度/秒,那么将GRY_X读数换算为角速度(顺时针)的公式为:gx=1000×GYRX32768g_x=1000\times \dfrac{GYR_X}{32768}gx=1000×32768GYRX

Register (Hex)Register (Decimal)Bit7Bit6Bit5Bit4Bit3Bit2Bit1Bit0
1B27XG_STYG_STZG_STFS_SEL[1]FS_SEL[0]
FS_SELFull Scale Range
0± 250 °/s
1± 500 °/s
2± 1000 °/s
3± 2000 °/s

Parameters:

  • XG_ST :Setting this bit causes the X axis gyroscope to perform self test.
  • YG_ST :Setting this bit causes the Y axis gyroscope to perform self test.
  • ZG_ST Setting this bit causes the Z axis gyroscope to perform self test.
  • FS_SEL 2-bit unsigned value. Selects the full scale range of gyroscopes

Register 107 – Power Management 1

This register allows the user to configure the power mode and clock source. It also provides a bit for resetting the entire device, and a bit for disabling the temperature sensor.

Register (Hex)Register (Decimal)Bit7Bit6Bit5Bit4Bit3Bit2Bit1Bit0
6B107DEVICE _RESETSLEEPCYCLE-TEMP_DISCLKSEL[2]CLKSEL[1]CLKSEL[0]
CLKSELClock Source
0Internal 8MHz oscillator
1PLL with X axis gyroscope reference
2PLL with Y axis gyroscope reference
3PLL with Z axis gyroscope reference
4PLL with external 32.768kHz reference
5PLL with external 19.2MHz reference
6Reserved
7Stops the clock and keeps the timing generator in reset

Parameters:

  • DEVICE_RESET
    When set to 1, this bit resets all internal registers to their default values. The bit automatically clears to 0 once the reset is done. The default values for each register can be found in Section 3.
  • SLEEP: When set to 1, this bit puts the MPU-60X0 into sleep mode.
  • CYCLE: When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle between sleep mode and waking up to take a single sample of data from active sensors at a rate determined by LP_WAKE_CTRL (register 108).
  • TEMP_DIS: When set to 1, this bit disables the temperature sensor.
  • CLKSEL: 3-bit unsigned value. Specifies the clock source of the device.

在这里插入图片描述

X轴Roll轴,Y轴Pitch轴

pitch=arccos⁡(accy2+accz2g)ifaccx>0,pitch<0pitch=\arccos(\dfrac{\sqrt{acc_y^2+acc_z^2}}{g})\quad if \ acc_x>0,pitch<0pitch=arccos(gaccy2+accz2)if accx>0,pitch<0

roll=arccos⁡(accx2+accz2g)ifaccy<0,roll<0roll=\arccos(\dfrac{\sqrt{acc_x^2+acc_z^2}}{g})\quad if \ acc_y<0,roll<0roll=arccos(gaccx2+accz2)if accy<0,roll<0

Arduino库Wire.h

BoardI2C / TWI pins
Uno, EthernetA4 (SDA), A5 (SCL)

Wire.requestFrom()

  • Syntax

    Wire.requestFrom(address, quantity)
    Wire.requestFrom(address, quantity, stop)

  • Parameters

    address: the 7-bit address of the device to request bytes from

    quantity: the number of bytes to request

    stop : boolean. true will send a stop message after the request, releasing the bus. false will continually send a restart after the request, keeping the connection active.

  • Returns

    byte : the number of bytes returned from the slave device

Wire.available()

  • Description

    Returns the number of bytes available for retrieval with read(). This should be called on a master device after a call to requestFrom() or on a slave inside the onReceive() handler.

    available() inherits from the Stream utility class.

  • Parameters

    None

  • Returns

    The number of bytes available for reading.

Wire.beginTransmission(address)

  • Description

    Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission().

  • Parameters

    address: the 7-bit address of the device to transmit to

  • Returns

    None

Wire.endTransmission()

  • Description

    Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write().

    As of Arduino 1.0.1, endTransmission() accepts a boolean argument changing its behavior for compatibility with certain I2C devices.

    If true, endTransmission() sends a stop message after transmission, releasing the I2C bus.

    If false, endTransmission() sends a restart message after transmission. The bus will not be released, which prevents another master device from transmitting between messages. This allows one master device to send multiple transmissions while in control.

    The default value is true.

  • Syntax

Wire.endTransmission()
Wire.endTransmission(stop)

  • Parameters

stop : boolean. true will send a stop message, releasing the bus after transmission. false will send a restart, keeping the connection active.

  • Returns

    byte, which indicates the status of the transmission:

    • 0:success
    • 1:data too long to fit in transmit buffer
    • 2:received NACK on transmit of address
    • 3:received NACK on transmit of data
    • 4:other error

Wire.write()

  • Description

    Writes data from a slave device in response to a request from a master, or queues bytes for transmission from a master to slave device (in-between calls to beginTransmission() and endTransmission()).

  • Syntax

    Wire.write(value)
    Wire.write(string)
    Wire.write(data, length)

  • Parameters

    value: a value to send as a single byte

    string: a string to send as a series of bytes

    data: an array of data to send as bytes

    length: the number of bytes to transmit

  • Returns

    byte: write() will return the number of bytes written, though reading that number is optional

#include <Wire.h>
byte val = 0;
void setup()
{Wire.begin(); // join i2c bus
}void loop()
{Wire.beginTransmission(44); // transmit to device #44 (0x2c)// device address is specified in datasheetWire.write(val);             // sends value byte  Wire.endTransmission();     // stop transmittingval++;        // increment valueif(val == 64) // if reached 64th position (max){val = 0;    // start over from lowest value}delay(500);
}

Wire.read()

  • Description

    Reads a byte that was transmitted from a slave device to a master after a call to requestFrom() or was transmitted from a master to a slave. read() inherits from the Stream utility class.

  • Syntax

    Wire.read()

  • Parameters

    none

  • Returns

    The next byte received

#include <Wire.h>
void setup()
{Wire.begin();        // join i2c bus (address optional for master)Serial.begin(9600);  // start serial for output
}void loop()
{Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2while(Wire.available())    // slave may send less than requested{char c = Wire.read();    // receive a byte as characterSerial.print(c);         // print the character}delay(500);
}

Wire.setClock()

  • Description

    This function modifies the clock frequency for I2C communication. I2C slave devices have no minimum working clock frequency, however 100KHz is usually the baseline.

  • Syntax

    Wire.setClock(clockFrequency)

  • Parameters

    clockFrequency: the value (in Hertz) of desired communication clock. Accepted values are 100000 (standard mode) and 400000 (fast mode). Some processors also support 10000 (low speed mode), 1000000 (fast mode plus) and 3400000 (high speed mode). Please refer to the specific processor documentation to make sure the desired mode is supported.

  • Returns

    None

Wire.onReceive(handler)

  • Description

    Registers(注册) a function to be called when a slave device receives a transmission from a master.

  • Parameters

    handler: the function to be called when the slave receives data; this should take a single int parameter (the number of bytes read from the master) and return nothing, e.g.: void myHandler(int numBytes)

  • Returns

    None

Wire.onRequest(handler)

  • Description

    Register a function to be called when a master requests data from this slave device.

  • Parameters

    handler: the function to be called, takes no parameters and returns nothing, e.g.: void myHandler()

  • Returns

    None

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_20199.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

优雅的处理参数校验以及异常

1、前言 编写控制层时&#xff0c;我们可能会自己去校验请求参数&#xff0c;就会出现这样的代码&#xff1a; if (StringUtils.isEmpty(memberSid)) {return new JsonResult(false, "参数memberSid为空"); } if (null test) {return new JsonResult(false, "…

油溶性PbS量子点近红外发射光PL800nm-1600nm

油溶性PbS量子点近红外发射光PL800nm-1600nm 油溶性PbS量子点产品&#xff0c;表面由疏水配体包覆&#xff0c;平均的量子产率为50%&#xff0c;储存时应避免阳光直射&#xff0c;4度密封暗处保存&#xff0c;可以为客户订制生产800nm&#xff5e;1600nm任一波长不同克数的产品…

叶毓睿:元宇宙发展与治理中,治理的主体是谁?治理的对象是谁?

中国移联元宇宙产业委员会联席秘书长、《元宇宙十大技术》著者之一、高效能服务器和存储技术国家重点实验室首席研究员叶毓睿&#xff1a;治理之可能性的关键在于延续性和开创性。 2022年9月24日&#xff0c;元宇宙产业委特别筹备的“发展与治理”2022元宇宙共治大会暨《元宇宙…

【JT-1/2电子式同步检查继电器】

1 用途 JT-1型同步检查继电器用于两端供电线路的自动重合闸线路中&#xff0c;其作用在于检查线路上电压的存在及线路上和变电站汇流排上电压向量间的相角差。 2 结构和原理 2.1 本继电器采用嵌入式安装&#xff0c;其主体部分系插拔式结构 2.2 本继电器主体部分与DT-1型同…

【Python基础面向对象】self、类变量和实例变量、__init__

哈喽兄弟们&#xff0c;我们接着上篇继续学习面向对象。 面向对象化编程所有的实例对象和实例方法都必须以self作为第一个参数&#xff0c;文章内容接上一章&#xff1a;Python面向对象编程基础之面向对象思想和特点、类和对象。这个系列将会很详细的解释清楚Python面向对象编程…

java实现多层级目录树详解

一&#xff0c;引言 在开发中&#xff0c;经常遇到前端需要实现一个多层级的目录树&#xff0c;那么后端就需要根据这种结构返回对应的数据&#xff0c;因此在这里记录一下本人在开发中是如何实现这个多层级的目录树。 二&#xff0c;建表建库 在建表时&#xff0c;需要注意…

(附源码)计算机毕业设计SSM悠哈出租车管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

模拟IC设计到底怎么学?给初学者一点建议

想必大家都知道&#xff0c;模拟IC设计非常难学。就拿最普遍的晶体管来说&#xff0c;我们分析它的时候必须首先分析直流偏置&#xff0c;其次在分析交流输出电压。可以说&#xff0c;这是一项相当复杂的工作。有些朋友一直吐槽模拟IC设计真的非常难学&#xff0c;那么到底该怎…

SWAT模型 建模方法、实例应用、高级进阶

目录 第一部分&#xff1a;【建模及实践】SWAT模型在水文水资源、面源污染模拟中的实践技术应用及典型案例分析 第二部分&#xff1a;【高级进阶】SWAT模型高阶应用暨无资料地区建模、不确定分析与气候变化、土地利用对面源污染影响模型改进及案例分析 基于ArcGIS的SWAT模型是…

yolov5-6.1的完全使用手册,含模型训练测试(可训练自己的数据集)

安装yolov5 安装命令如下下所示&#xff0c;包含了下载yolov5-6.1&#xff0c;及相关包安装命令。yolov5项目目前已经更新到6.2&#xff0c;支持对图像数据的分类&#xff0c;但使用较为麻烦&#xff0c;因此仅以6.1为例进行说明。安装yolov5后&#xff0c;切记不要安装wandb&…

条件区域循环的Sumif

问题:Sumif条件为D12:D16,求和区域从E3:E8向右,条件区域为B3:D8三列循环 函数解决:=SUMIF(OFFSET($B$3:$B$8,,MOD(COLUMN(C1),3)),$D12,E$3:E$8) 思路: 利用Mod(Column(C1),3),右拉生成0、1、2、0、1、2……这样的循环数 利用Offset,从B3:B8起,右拉生成向右偏移0、1、…

国民技术MCU之串口烧录

国民技术MCU串口烧录 前言 在我们使用国民技术单片机的时候&#xff0c;一般是用JLink SWD来烧录调试固件。 但是在某些情况下&#xff0c;比如需要刷写固件的现场没有JLink工具&#xff0c;采用批量生产、或者MCU在程序上电后SWD功能没有正常运行&#xff08;变砖&#xff0…

数据库概述06(视图)

视图 常见的数据库对象 表TABLE 表是存储数据的逻辑单元&#xff0c;以行和列的形式存在&#xff0c;列就是字段&#xff0c;行就是记录 数据字典 就是系统表&#xff0c;存放数据库相关信息的表。系统表的数据通常由数据库系统维护&#xff0c;程序员通常不应该修改&#xf…

一些有关多线程的‘‘八股文‘‘?!

目录 一. 常见的锁策略: 二. CAS 三.synchronized原理 四. HashTable, HashMap, ConcurrentHashMap 之间的区别: 五. 死锁的成因, 和解决方案: 一. 常见的锁策略: 1.乐观锁 vs 悲观锁: 描述的是两种不同的加锁态度 乐观:预测锁冲突概率不高,因此做的工…

2022年NPDP新版教材知识集锦--【第一章节】(2)

【制定战略的工具】 SWOT分析&#xff1a;由四个英文单词的首字母组合而成&#xff0c;分别是优势(Strengths)、劣势(Weaknesses)、机会(Opportunities)和威胁(Threats)。 ⚫优势&#xff1a;某企业或项目优于其他企业或项目的特点。 ⚫劣势&#xff1a;某企业或项目不如其他…

python学习笔记:numpy库,使用matpotlib库绘图

目录 一.Numpy库 1.什么是numpy? 2.Numpy数组和原生Python array数组之间的区别 3.Numpy数组 ​编辑 4.numpy数组的运算 5.numpy的索引&#xff0c;切片 二.matplotlib 1.绘制直线 2.绘制曲线 3.散点图绘制 4.多界面绘制 5.柱形图绘制 6.3D图形绘制 一.Numpy库 1.…

数据库与MPP数仓(三十):pigsty部署

pigsty是pg的开箱即用版本,提供完善监控和高可用功能,高质量的国产开源工程,监控面板非常详尽,保姆级别的文档; 参考:腾讯云VPC部署 | Pigsty 参考:Releases Vonng/pigsty GitHub pigsty源码基本上都是使用ansible的playbook编写,使用ansible同时配置多台机器,在角…

基于Ubuntu20.04安装Nvidia驱动、Cuda和CudNN

基于Ubuntu20.04安装Nvidia驱动、Cuda和CudNN 前言 nvidia驱动&#xff0c;cuda&#xff0c;cudnn三者关系 1 nvidia驱动 1.1 nvidia驱动安装 首先Nvidia驱动应该是最好理解的&#xff0c;它就是GPU显卡的软件驱动程序&#xff0c;和计算机其他的硬件驱动一样。Nvidia官网提…

设计管理工具的三个基本类别

什么是用于管理设计过程的优质设计管理工具?成功管理设计项目需要正确的工具和软件。设计管理工具的三个基本类别是&#xff1a;通讯工具、时间线管理工具、文件和资源管理工具。 1、通讯工具 沟通工具使团队成员能够保持在同一页面上&#xff0c;无论他们的工作地点如何。他们…

app自动化测试之Andriod WebView如何测试

Hybrid App&#xff08;混合模式移动应用&#xff09;是介于 Web-app、Native-app 之间的 app&#xff0c;本质上是 Native-app 中嵌入 WebView 组件&#xff0c;在 WebView 组件里可以访问 Web App。Hybrid App 在给用户良好交互体验的同时&#xff0c;还具备了 Web App 的跨平…