2017-09-13 02:58:18 -04:00
|
|
|
//
|
2013-09-30 11:03:06 -04:00
|
|
|
// FILE: set2standby.pde
|
|
|
|
// AUTHOR: Rob Tillaart
|
2017-09-13 02:58:18 -04:00
|
|
|
// VERSION: 0.1.1
|
|
|
|
// PURPOSE: Reset HMC6352 to standby mode
|
|
|
|
// (esp if it is struck in continuous mode - Arduino)
|
2013-09-30 11:03:06 -04:00
|
|
|
//
|
2017-09-13 02:58:18 -04:00
|
|
|
// HISTORY:
|
2013-09-30 11:03:06 -04:00
|
|
|
// 0.1.00 - 2011-04-12 initial version
|
2017-09-13 02:58:18 -04:00
|
|
|
// 0.1.1 - 2017-09-13 renamed to .ino; fix wire.receive
|
|
|
|
//
|
2013-09-30 11:03:06 -04:00
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
// All disclaimers apply use at own risk
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
|
|
|
#define WIRE_WRITE Wire.write
|
|
|
|
#define WIRE_READ Wire.read
|
|
|
|
#else
|
|
|
|
#define WIRE_WRITE Wire.send
|
|
|
|
#define WIRE_READ Wire.receive
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int HMC = 0x21;
|
2013-09-30 11:03:06 -04:00
|
|
|
int ledPin = 13;
|
|
|
|
boolean ledState = LOW;
|
|
|
|
byte value;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.print("HMC6352 : start - ");
|
|
|
|
Serial.println(HMC, HEX);
|
|
|
|
|
|
|
|
pinMode(ledPin, OUTPUT);
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
delay(1000); // give all things time to start
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// flashing means not blocking
|
|
|
|
ledState = !ledState;
|
|
|
|
digitalWrite(ledPin, ledState);
|
|
|
|
|
|
|
|
// write stdby mode to RAM 0x74 and do an L command immediately after it
|
|
|
|
// this is done to "break through" the continuous mode
|
|
|
|
// pull out 5 volt if it reads back 0x50
|
|
|
|
Wire.beginTransmission(HMC);
|
2017-09-13 02:58:18 -04:00
|
|
|
WIRE_WRITE('G');
|
|
|
|
WIRE_WRITE(0x74);
|
|
|
|
WIRE_WRITE(0x50);
|
|
|
|
WIRE_WRITE('L');
|
|
|
|
// WIRE_WRITE('O'); optional reset
|
2013-09-30 11:03:06 -04:00
|
|
|
x = Wire.endTransmission();
|
|
|
|
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);
|
2017-09-13 02:58:18 -04:00
|
|
|
WIRE_WRITE('r');
|
|
|
|
WIRE_WRITE(0x07);
|
2013-09-30 11:03:06 -04:00
|
|
|
x = Wire.endTransmission();
|
|
|
|
delay(10);
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int cnt = Wire.requestFrom(HMC, 1);
|
|
|
|
if (cnt == 1)
|
|
|
|
{
|
|
|
|
value = WIRE_READ();
|
|
|
|
Serial.print("Current Mode: ");
|
|
|
|
Serial.println((int)value, BIN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Serial.println("Error...");
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
// END OF FILE
|