Borrar filtros
Borrar filtros

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

7 visualizaciones (últimos 30 días)
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

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 28 de Mzo. de 2019
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.

Más respuestas (0)

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by