Difficulty with i2c Read Register. Not enough information in the doc
4 views (last 30 days)
Show older comments
Robert
on 24 Jan 2017
Commented: Walter Roberson
on 7 Apr 2020
So i am working with an I2C device and reading in 8 bit register data
The problem is the following. The doc does not allow for data to be read in a specific format.
The register is currently housing data in a 2,s complement format
When i read from the register its giving decimal answers.
This is a problem because i have no idea what conversion its doing in the background. It sure doesn't know that what its reading is 2s complement so I'm assuming the decimal number I'm getting back is wrong also.
How can i just read the register in pure binary?
There is nothing in the doc
0 Comments
Accepted Answer
Walter Roberson
on 24 Jan 2017
If you are using arduino and read() of an i2cdev object, then the transfer always binary. As is always the case, by default MATLAB displays binary numbers in decimal . You can use dec2bin() to display it as binary.
I suspect that want you want is to pass 'int8' to the read() routine.
8 Comments
Walter Roberson
on 7 Apr 2020
Understanding the I2C Bus
Data is transferred Most Significant Bit (MSB) first.
As the bit order for I2C is fixed, there is no possibility that the bit order for any given device should be the other way around. This is not a negotiable property of the device.
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!