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

조회 수: 7 (최근 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
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 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