2's compliment possible esp8266 Arduino issues
Posted: Tue Nov 24, 2015 3:39 pm
void BMP085::getCalData() {
readmem(CAL_AC1, 2, _buff);
ac1 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC2, 2, _buff);
ac2 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC3, 2, _buff);
ac3 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC4, 2, _buff);
ac4 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_AC5, 2, _buff);
ac5 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_AC6, 2, _buff);
ac6 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_B1, 2, _buff);
b1 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_B2, 2, _buff);
b2 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MB, 2, _buff);
mb = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MC, 2, _buff);
mc = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MD, 2, _buff);
md = ((int)_buff[0] <<8 | ((int)_buff[1]));
}
output notice ac2 ac3 mb mc are still in 2's compliment form
==========================================================
---cal data start---
ac1:7123
ac2:64415
ac3:51091
ac4:33914
ac5:25254
ac6:17421
b1:6515
b2:42
mb:32768
mc:53750
md:2665
---cal data end---
Now according to the bmp085 altimeter secs ac1 ac2 ac3 and B1,B2,MB MC MD are in 2's compliment notation
the code for ac1 as an example casts both bytes to (int) then bit wise or's them after first shifting one to the left 8 bits.
This doesn't appear to be working with the esp8266..easy enough to rewrite but troubling nonetheless since it presumably works on other platforms.
The HMC58X3 also has 2's compliment notational issues since it is 12 bit 2's compliment notation within a 16 bit register read a byte at a time via I2C
readmem(CAL_AC1, 2, _buff);
ac1 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC2, 2, _buff);
ac2 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC3, 2, _buff);
ac3 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_AC4, 2, _buff);
ac4 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_AC5, 2, _buff);
ac5 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_AC6, 2, _buff);
ac6 = ((unsigned int)_buff[0] <<8 | ((unsigned int)_buff[1]));
readmem(CAL_B1, 2, _buff);
b1 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_B2, 2, _buff);
b2 = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MB, 2, _buff);
mb = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MC, 2, _buff);
mc = ((int)_buff[0] <<8 | ((int)_buff[1]));
readmem(CAL_MD, 2, _buff);
md = ((int)_buff[0] <<8 | ((int)_buff[1]));
}
output notice ac2 ac3 mb mc are still in 2's compliment form
==========================================================
---cal data start---
ac1:7123
ac2:64415
ac3:51091
ac4:33914
ac5:25254
ac6:17421
b1:6515
b2:42
mb:32768
mc:53750
md:2665
---cal data end---
Now according to the bmp085 altimeter secs ac1 ac2 ac3 and B1,B2,MB MC MD are in 2's compliment notation
the code for ac1 as an example casts both bytes to (int) then bit wise or's them after first shifting one to the left 8 bits.
This doesn't appear to be working with the esp8266..easy enough to rewrite but troubling nonetheless since it presumably works on other platforms.
The HMC58X3 also has 2's compliment notational issues since it is 12 bit 2's compliment notation within a 16 bit register read a byte at a time via I2C