两种访问I2C总线的方法有什么区别?
What's the difference between two methods of accessing thorugh I2C bus?
我看到了两种从I2C总线请求数据的不同方法:
方法一:
Wire.beginTransmission(MPU);
Wire.write(0x43); // Gyro data first register address 0x43
Wire.endTransmission(false);
//https://www.arduino.cc/en/Reference/WireEndTransmission
//false will send a restart, keeping the connection active.
Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;
方法2:
Wire.beginTransmission(0b1101000); //I2C address of the MPU //Accelerometer and Temperature reading (check 3.register map)
Wire.write(0x3B); //Starting register for Accel Readings
Wire.endTransmission();
Wire.requestFrom(0b1101000,8); //Request Accel Registers (3B - 42)
while(Wire.available() < 8);
accelX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX
accelY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY
accelZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ
temp = Wire.read()<<8| Wire.read();
似乎第一种方法没有终止传输,即Wire.endTransmission(false(,而第二种方法没有指定。 它们之间有什么区别?以及哪一个更好,即响应时间/循环时间。
另外,是否
0b1101000 and 0x3B(the register address for Accel in Method 2)
彼此平等?
一个是请求陀螺仪读数,其他加速度计读数,它们是不同的东西。 与您的另一个问题相同,0b1101000 是 MPU 的地址,而 0x3B 是加速度计寄存器地址(所以不一样(,您可能应该阅读您为此使用的库,或者如果您不使用任何库,您可以在 Arduino 库选项中找到一些(无论它叫什么,都有一段时间没有使用它了(。
如果您不想使用库,请阅读 MPU 的数据表以更好地理解。
根据它是 MPU6 系列、MPU9 系列还是其他制造商,情况会发生变化,但大多数已经构建了库,我建议您使用它们,除非您有兴趣从头开始工作,这可能会变得相当复杂非常快。
相关文章:
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 返回常量对象引用 (getter) 和仅返回字符串有什么区别?
- Qt:remove() 和 rmdir() 有什么区别
- 这 4 个 lambda 表达式之间有什么区别?
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- typedef 枚举和枚举类有什么区别?
- &C::c 和 &(C::c) 有什么区别?
- ascii 和 unicode 在处理级别有什么区别吗?
- C 中的常量限定符和 C++ 中的常量限定符有什么区别?
- "ABC" 和 "ABC" ) 在C++中有什么区别?
- 空指针常量 (nullptr)、空指针值和空成员指针值之间有什么区别?
- 引用捕获和在 lambda 中通过引用发送参数有什么区别 (C++)
- 两种访问I2C总线的方法有什么区别?
- 两种模板示例有什么区别?
- 这两种C++语法之间有什么区别?
- lua 5.0.2 模块和 5.3.5 有什么区别?
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- std::enable_if 和 std::enable_if_t 有什么区别?