Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: HMC5883L.cpp
- Revision:
- 8:8b6e984df00b
- Parent:
- 7:38050f18f60a
diff -r 38050f18f60a -r 8b6e984df00b HMC5883L.cpp
--- a/HMC5883L.cpp Fri Nov 15 12:19:58 2019 +0000
+++ b/HMC5883L.cpp Mon Feb 24 07:45:19 2020 +0000
@@ -61,7 +61,8 @@
cmd[0] = CONFIG_A_REG; // register a address
cmd[1] = config;
- i2c_.write(I2C_ADDRESS, cmd, 2);
+ i2c_.write(0x3C, cmd, 2);
+ //i2c_.write(I2C_ADDRESS, cmd, 2);
}
void HMC5883L::setConfigurationB(char config)
@@ -70,14 +71,16 @@
cmd[0] = CONFIG_B_REG; // register b address
cmd[1] = config;
- i2c_.write(I2C_ADDRESS, cmd, 2);
+ i2c_.write(0x3C, cmd, 2);
+ //i2c_.write(I2C_ADDRESS, cmd, 2);
}
char HMC5883L::getConfigurationA()
{
char cmd[2];
cmd[0] = CONFIG_A_REG; // register a address
- i2c_.write(I2C_ADDRESS, cmd, 1, true);
+ i2c_.write(0x3C, cmd, 1, true);
+ //i2c_.write(I2C_ADDRESS, cmd, 1, true);
i2c_.read(I2C_ADDRESS, &cmd[1], 1, false);
return cmd[1];
}
@@ -86,7 +89,8 @@
{
char cmd[2];
cmd[0] = CONFIG_B_REG; // register b address
- i2c_.write(I2C_ADDRESS, cmd, 1, true);
+ i2c_.write(0x3C, cmd, 1, true);
+ //i2c_.write(I2C_ADDRESS, cmd, 1, true);
i2c_.read(I2C_ADDRESS, &cmd[1], 1, false);
return cmd[1];
}
@@ -96,14 +100,16 @@
char cmd[2];
cmd[0] = MODE_REG; // mode register address
cmd[1] = mode;
- i2c_.write(I2C_ADDRESS,cmd,2);
+ i2c_.write(0x3C, cmd, 2);
+ //i2c_.write(I2C_ADDRESS,cmd,2);
}
char HMC5883L::getMode()
{
char cmd[2];
cmd[0] = MODE_REG; // mode register
- i2c_.write(I2C_ADDRESS, cmd, 1, true);
+ i2c_.write(0x3C, cmd, 1, true);
+ //i2c_.write(I2C_ADDRESS, cmd, 1, true);
i2c_.read(I2C_ADDRESS, &cmd[1], 1, false);
return cmd[1];
}
@@ -112,7 +118,8 @@
{
char cmd[2];
cmd[0] = STATUS_REG; // status register
- i2c_.write(I2C_ADDRESS, cmd, 1, true);
+ i2c_.write(0x3C, cmd, 1, true);
+ //i2c_.write(I2C_ADDRESS, cmd, 1, true);
i2c_.read(I2C_ADDRESS, &cmd[1], 1, false);
return cmd[1];
}
@@ -122,11 +129,15 @@
char cmd[2];
char data[6];
cmd[0] = 0x03; // starting point for reading
- i2c_.write(I2C_ADDRESS, cmd, 1, true); // set the pointer to the start of x
+ //i2c_.write(0x3c, cmd, 1, true);
+ //i2c_.write(I2C_ADDRESS, cmd, 1, true); // set the pointer to the start of x
i2c_.read(I2C_ADDRESS, data, 6, false);
for(int i = 0; i < 3; i++) // fill the output variables
output[i] = int16_t(((unsigned char)data[i*2] << 8) | (unsigned char)data[i*2+1]);
+
+ i2c_.write(0x3c, cmd, 1, true);
+
}
double HMC5883L::getHeadingXY(int Calib_x,int Calib_y)