フィルターのクリア

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

7 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2019 年 2 月 15 日
編集済み: MathWorks Support Team 2019 年 3 月 28 日
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
MathWorks Support Team 2019 年 3 月 28 日
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 Center および File ExchangeModeling についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by