2017-09-13 02:58:18 -04:00
|
|
|
//
|
|
|
|
// FILE: set2continuous.ino
|
2013-09-30 11:03:06 -04:00
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:16:22 -05:00
|
|
|
// VERSION: 0.2.0
|
|
|
|
// PURPOSE: Reset HMC6352 to continuous mode without library
|
2017-09-13 02:58:18 -04:00
|
|
|
//
|
|
|
|
// HISTORY:
|
|
|
|
// 0.1.0 - 2011-04-12 initial version
|
|
|
|
// 0.1.1 - 2017-09-13 renamed to .ino; fix wire.receive
|
2020-11-27 05:16:22 -05:00
|
|
|
// 0.2.0 2020-06-13 refactor
|
2013-09-30 11:03:06 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int HMC = 0x21;
|
2013-09-30 11:03:06 -04:00
|
|
|
int ledPin = 13;
|
|
|
|
boolean ledState = LOW;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.begin(115200);
|
2013-09-30 11:03:06 -04:00
|
|
|
Serial.print("HMC6352 : start - ");
|
|
|
|
Serial.println(HMC, HEX);
|
|
|
|
|
|
|
|
pinMode(ledPin, OUTPUT);
|
2020-11-27 05:16:22 -05:00
|
|
|
digitalWrite(ledPin, ledState);
|
2013-09-30 11:03:06 -04:00
|
|
|
|
|
|
|
Wire.begin();
|
2020-11-27 05:16:22 -05:00
|
|
|
|
2013-09-30 11:03:06 -04:00
|
|
|
delay(1000); // give all things time to start
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// flashing means not blocking
|
|
|
|
ledState = !ledState;
|
|
|
|
digitalWrite(ledPin, ledState);
|
|
|
|
|
|
|
|
// write continuous mode to RAM 0x74 and do an L command immediately after it
|
|
|
|
// pull out 5 volt if it reads back 0x72
|
|
|
|
Wire.beginTransmission(HMC);
|
2020-11-27 05:16:22 -05:00
|
|
|
Wire.write('G');
|
|
|
|
Wire.write(0x74);
|
|
|
|
Wire.write(0x72); // 20 Hz | Reset = True | CONT
|
|
|
|
Wire.write('L');
|
|
|
|
// Wire.write('O'); optional reset
|
|
|
|
Wire.endTransmission();
|
2013-09-30 11:03:06 -04:00
|
|
|
delay(10);
|
2017-09-13 02:58:18 -04:00
|
|
|
|
2013-09-30 11:03:06 -04:00
|
|
|
// Read the EEPROM value for feedback as this is the next startup value
|
|
|
|
Wire.beginTransmission(HMC);
|
2020-11-27 05:16:22 -05:00
|
|
|
Wire.write('r');
|
|
|
|
Wire.write(0x07);
|
|
|
|
Wire.endTransmission();
|
2013-09-30 11:03:06 -04:00
|
|
|
delay(10);
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int cnt = Wire.requestFrom(HMC, 1);
|
|
|
|
if (cnt == 1)
|
|
|
|
{
|
|
|
|
Serial.print("Current Mode: ");
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.println((int)Wire.read(), BIN);
|
2017-09-13 02:58:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.print("Error... : ");
|
|
|
|
Serial.println(cnt);
|
2017-09-13 02:58:18 -04:00
|
|
|
}
|
|
|
|
}
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
// END OF FILE
|