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.
Dependencies: ConfigFile SDFileSystem mbed
Fork of LAURUS_program by
Diff: HMC5883L/HMC5883L.cpp
- Revision:
- 0:bc6f14fc60c7
- Child:
- 1:6cd6d2760856
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HMC5883L/HMC5883L.cpp Fri May 15 17:24:32 2015 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "HMC5883L.h"
+
+HMC5883L::HMC5883L(I2C* i2c) {
+ this->i2c = i2c;
+}
+
+HMC5883L::~HMC5883L() {
+ i2c = NULL;
+}
+
+int HMC5883L::init() {
+ return 1;
+}
+
+int HMC5883L::read() {
+ char cmd[2] = {0x02, 0x01};
+ int ret = i2c->write(hmc_addr, cmd, 2);
+ if(ret != 0) return 0;
+
+ cmd[0] = 0x03;
+ i2c->write(hmc_addr, cmd, 1);
+ i2c->read(hmc_addr | 0x01, data.reg, 6, true);
+
+ // データのHとLが逆に読み込まれているのでスワップする
+ for(int i=0; i<3; i++) {
+ char temp = 0;
+ temp = data.reg[i*2];
+ data.reg[i*2] = data.reg[i*2+1];
+ data.reg[i*2+1] = temp;
+ }
+
+ int16_t temp = data.value[1];
+ data.value[1] = data.value[2];
+ data.value[2] = temp;
+
+ return 1;
+}
\ No newline at end of file
