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 ?
Edit: Changing int to int16_t works.
I propose to change
1. raw data types:
struct MagnetometerRaw
{
int16_t XAxis;
int16_t YAxis;
int16_t ZAxis;
};
2. includes:
#include WProgram.h
to
#include <Arduino.h>
in HMC5883L.cpp
3. read and write methods of Wire library:
In HMC5883L.cpp change
Wire.send to
Wire.write and
Wire.receive to
Wire.read