I'm using SPI to communicate with a MPU6000.
The used code worked with the Arduino Uno, with the Teensy 3.1 I get the same values AS LONG AS THEY ARE POSITIV.
Negative values are shown like 2^16 - "the value it should have".
My question is, what is wrong?
Why are these values not interpreted as negative values?
The used code worked with the Arduino Uno, with the Teensy 3.1 I get the same values AS LONG AS THEY ARE POSITIV.
Negative values are shown like 2^16 - "the value it should have".
My question is, what is wrong?
Why are these values not interpreted as negative values?
Code:
void setup()
{
...
// MPU6000 chip select setup
pinMode(MPU6000_CHIP_SELECT_PIN, OUTPUT);
digitalWrite(MPU6000_CHIP_SELECT_PIN, HIGH);
// SPI initialization
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setBitOrder(MSBFIRST); // data delivered MSB first
SPI.setDataMode(SPI_MODE0);
...
}
byte MPU6000_SPI_read(byte reg)
{
byte dump;
byte return_value;
byte addr = reg | 0x80; // Set most significant bit
digitalWrite(MPU6000_CHIP_SELECT_PIN, LOW);
dump = SPI.transfer(addr);
return_value = SPI.transfer(0);
digitalWrite(MPU6000_CHIP_SELECT_PIN, HIGH);
return(return_value);
}
void loop() {
...
byte_H = MPU6000_SPI_read(MPUREG_ACCEL_XOUT_H);
byte_L = MPU6000_SPI_read(MPUREG_ACCEL_XOUT_L);
int accelX = (byte_H<<8)| byte_L;
...
Serial.println(accelX);
...
}