MAG3110 Virgo robot adaptation
Fork of MAG3110 by
Diff: MAG3110.cpp
- Revision:
- 15:58c62b985e68
- Parent:
- 14:73a4a09a49af
diff -r 73a4a09a49af -r 58c62b985e68 MAG3110.cpp --- a/MAG3110.cpp Fri Sep 09 10:48:07 2016 +0000 +++ b/MAG3110.cpp Sat Sep 10 05:49:44 2016 +0000 @@ -12,31 +12,43 @@ { char cmd[2]; + cmd[0] = MAG_CTRL_REG2; + cmd[1] = 0b1 << 4; //reset overexposure + _i2c.write(MAG_ADDR, cmd, 2); + + wait_ms(100); + cmd[0] = MAG_CTRL_REG1; cmd[1] = 0x00; //Puts device in Standby mode _i2c.write(MAG_ADDR, cmd,2); cmd[0] = MAG_CTRL_REG2; - cmd[1] = 0x90; //Set Automatic Magnetic Sensor Reset bit, and reset overexposure + cmd[1] = 0x80; //Set Automatic Magnetic Sensor Reset bit _i2c.write(MAG_ADDR, cmd, 2); cmd[0] = MAG_CTRL_REG1; cmd[1] = 0x01; //Set ODR=80Hz and OSR=16 and set device to active mode. _i2c.write(MAG_ADDR, cmd, 2); - char data_bytes[7]; - data_bytes[0]=MAG_OFF_X_MSB; //Write offset values to X,Y,Z registers + char data_bytes[3]; + data_bytes[0]=MAG_OFF_X_MSB; //Write offset values to X register data_bytes[1] = (off_x & 0xFF00) >> 8; data_bytes[2] = (off_x & 0xFF); - - data_bytes[3] = (off_y & 0xFF00) >> 8; - data_bytes[4] = (off_y & 0xFF); + _i2c.write(MAG_ADDR,data_bytes,3); + wait_ms(10); - data_bytes[5] = (off_z & 0xFF00) >> 8; - data_bytes[6] = (off_z & 0xFF); - - _i2c.write(MAG_ADDR,data_bytes,7); + data_bytes[0]=MAG_OFF_Y_MSB; //Write offset values to Y register + data_bytes[1] = (off_y & 0xFF00) >> 8; + data_bytes[2] = (off_y & 0xFF); + _i2c.write(MAG_ADDR,data_bytes,3); + wait_ms(10); + + data_bytes[0]=MAG_OFF_Z_MSB; //Write offset values to Z register + data_bytes[1] = (off_z & 0xFF00) >> 8; + data_bytes[2] = (off_z & 0xFF); + _i2c.write(MAG_ADDR,data_bytes,3); + wait_ms(10); } // Read a single byte form 8 bit register, return as int