I've tested it with Arduino Pro mini, it is OK.
But the result on Due is incorrect.
It seems not consider the 2's complement.
the attached image shows Due not consider 2's complement.
and following data come from I2C sniffer.
-------------------- Start to Monitor I2C / SMBus / PMBus Procotol --------------------
-------------------- All data will be monitored and display on screen -----------------
[S] 3C 02 00 [P]
[S] 3C 03 [P]
[S] 3D 00 F3 01 52 FF 82# [P]
for 2's complement, 0xFF82 should be -126 not 65410.
Could somebody tell me how to fix this issue?
Thanks!
I confirm this.
In HMC5883L Library we read two's 8-bit registers ( MSB and LSB) and create from this16-bit signed int value by shift most significant byte by 8 and do inclusive OR with least significant byte: int value = (MSB << 8 ) | LSB;
Registers are stored in uint8_t (from <inttypes.h>) buffers.
As I understand what cmaglie said: an int type was 16-bits on other Arduino boards, so casting by shifting and OR was OK because sign bit was on right place.
Arduino Due using 32-bits integers so when we shift by 8 and do OR sign bit is 16 bit (not 32) and while casting we get wrong value ??
I will try with 16-bits integers as cmaglie said but I want to know how to change it in correct (efficient) way ?