The HMC6352 is a simple compass chip with an I2C interface. If your next unmanned vehicle needs a compass, check out this chip. It has multiple operating modes that balance power use and update frequency. Continuous acquisition provides rapid heading updates, while query acquisitions save power by only measuring only when it’s needed.

Thanks to SparkFun for sending this part to demo. If you don’t want to solder the 24pin lead-less chip yourself, you can get it on a breakout board at SparkFun.

Demo: is a weekly series that demonstrates devices with the Bus Pirate. Come back next Monday for another all new demo.

You can preorder assembled Bus Pirate hardware at Seeed Studio for $30, including worldwide shipping.


Device: Honeywell Magnetic Sensor (HMC6352) on breakout board ($34.95).
Bus: I2C (pull-up resistors required).
Power requirements: 2.7-5.2 volts.
References: datasheet, SparkFun breakout board.
Complete Bus Pirate session log for this demonstration.

Bus Pirate HMC6352
MOSI SDA
CLOCK SCL
+3.3volts out VCC
GND GND
Vpullup VCC

We connected the Bus Pirate to the breakout board as shown in the table above. The compass is powered by the Bus Pirate’s on-board 3.3volt supply. I2C is a high-impedance bus that requires pull-up resistors, so we used the on-board pull-up resistors with the Vpu pin connected to the 3.3volt power supply.

Bus Pirate setup

Press ‘m’ for the mode menu and choose I2C. Configure the I2C library for any speed.

At the I2C prompt, enable the power supplies (W) and on-board pull-up resistors (menu p). Get a voltage report (v) to verify that the power supplies are active and that the Vpullup pin is connected to the 3.3volt supply.

Interfacing the chip

I2C>(1) <<<I2C address scan macro
Searching 7bit I2C address space.
Found devices at:
0x42(0x21 W) 0x43(0x21 R)
I2C>

I2C devices respond to a read and write address. The I2C address for the HMC6352 is on page 3 of the datasheet. We used the Bus Pirate I2C address search macro as a shortcut. This devices responds to 0x42 and 0x43.

Unlike most I2C devices, the HMC6352 I2C address can be modified by writing a new value to the internal EEPROM. Read more about this feature under I2C slave address on page 7 of the datasheet.

I2C>[0x42 0x41]
I2C START BIT
WRITE: 0x42 ACK <<<HMC6352 write address
WRITE: 0x41 ACK <<<‘A’, acquire compass heading
I2C STOP BIT
I2C>

The HMC6352 has a lot of advanced features like calibration, power-saving sleep features, and continuous reading modes. We’re going to demonstrate the bare minimum requirements to get a single compass measurement from the chip.

Start the I2C transaction with a start bit ([). Send the write address (0x42) and ‘A’ to start a heading acquisition. End the I2C transaction with a stop bit (]).

I2C>[0x43 rr]
I2C START BIT
WRITE: 0x43 ACK <<<HMC6352 read address
READ: 0x0B ACK  <<< compass heading MSB
READ: 0x7F NACK <<<compass heading LSB
I2C STOP BIT
I2C>

Read two bytes back to get the heading.  The fist byte is the most significant 8bits of the heading, the second byte is the least significant 8bits. The heading is given in 0.1degree resolution.

0x0b7f is 2943 in decimal, divide by ten to find the degree heading of 294.3degrees (WNW).

I2C>[0x42 0x41]
I2C START BIT
WRITE: 0x42 ACK <<<HMC6352 write address
WRITE: 0x41 ACK<<<‘A’, acquire compass heading
I2C STOP BIT
I2C>[0x43 rr]
I2C START BIT
WRITE: 0x43 ACK <<<HMC6352 read address
READ: 0x00 ACK <<< compass heading MSB
READ: 0x5A NACK <<< compass heading LSB
I2C STOP BIT
I2C>

We rotate the compass and try it again. This time we get 0x005A (90 decimal), divide by ten to find a heading of 9degrees (North).

Taking it further

Check the Bus Pirate manual for a complete list of chip demonstrations. Requests are always appreciated.

Advertisements