How do I read int16 data using the Arduino I2C Support Package?

6 次查看(过去 30 天)
How do I read int16 data using the Arduino I2C Support Package?
Output data from the accelerometer I'm using is 16-bit Two's Complement according to the data sheet (attached). When I set the data size to N=6 (6 bytes of data from registers 0x32 - 0x37), I see 5 lines rather than 3, 1 for each axis. Also, only 1 line actually seems to be showing acceleration data. If I up the data size to 8, there are 3 lines that appear to be showing acceleration data along with extra lines.
So it seems there is an issue with packaging the data from the accelerometer in two's complement format into a format that would be readable on my end. How do I figure this out?
The I2C block

采纳的回答

MathWorks Support Team
If the data is twos complement, it means that it is signed data. Since the I2C Read block only supports "int8" and "uint16" data types, you will just want to read the bytes using the I2C Read block and then use the Byte Pack and Byte Unpack blocks to reformat it into the "int16" data type. The attached model provides an example of how to do this.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

标签

尚未输入任何标签。

产品


版本

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by