Go Down

Topic: Problems with HMC5843 (Read 6099 times) previous topic - next topic


Hello people,

Today I just got out of a three week struggle trying to get TWI working on my Arduino. Everything was done correctly, but it simply didn't work. It magically starting working again today (I didn't change anything) and seems very stable with my triple axis accelerometer and gyroscope but there seems to be a problem when I try to communicate with the HMC5843.

I'm currently using the Wire.h library (still trying to work out my own twi functions). I wrote the code such that it only tries to access the Identification Register A followed by a few configurations and that if any of these are unsuccessful, loop the sequence and try again. What usually happens is that it loops over and over again, showing that "2" is returned by the Wire.endTransmission() function, which supposedly means "received NACK on transmit of address" every time I send the address.

Occasionally, I manage to read the Identification Register A correctly, and also manage to get the entire setup sequence done. So I tried reading some data, and it turned out to be rubbish (same, constant values throughout X, Y and Z). However, it rarely manages to read any register.

According to some posts I found, this problem is associated with a wrong capacitor in previous versions of the Sparkfun breakout board. I have the latest version with the 4.7uF ceramic capacitor though. I'm also quite certain the problem isn't with the my TWI bus, since I initialise both the accelerometer and gyroscope right before I try to do so with the magnetometer.

Can anyone suggest some tests I can do to find the problem/point me in the right direction? I'd greatly appreciate any help! Thank you!

Bo Xuan

Nov 29, 2010, 04:48 pm Last Edit: Nov 29, 2010, 04:51 pm by fax8 Reason: 1
Well, the first thing you should try is run some "known to be working code" .. you can get some at: http://www.varesano.net/blog/fabio/first-steps-hmc5843-arduino-verify-accuracy-its-results (bottom of the page _11_hmc5843_calibrazione.tar_.gz)

Writing everything by yourself, even the TWI library, is surely a suicide. There are lot of nice libraries available in the Arduino community. Use them!

So, try the code in the linked webpage, and tell us if that worked.

Simply extract the archive, it will create a folder. Place it under your sketches directory.



Thanks for replying. Sorry I forgot to mention that I already tried code found online.

I downloaded the HMC5843 Driver library and ran the test sketch. I didn't change anything, it simply read the same values but didn't seem to receive the NACKs.

Bo Xuan

May I see a picture of your connections?

Mine looks like http://www.varesano.net/files/IMU6DOF_Arduino_connections.jpg



Here's mine, sorry about the mess of wires.

Bo Xuan

This looks overcomplicated. I'm connecting the HMC5843 directly to Arduino basically using these connections http://www.varesano.net/files/adxl345_arduino_schematics.jpg (that's for an ADXL345 acc but you can use the same on the HMC5843 .. just don't care of CS and SDO). I don't use any logic level shifter nor any voltage regulator.

So, my suggestion would be.. get rid of everything you can. The logic level shifter, the voltage regulator, and the acc and gyro. Connect only the HMC5843, the two resistors and give it a try.

It's really easy to get something wrong in your setup that's why I'd like you to try keeping everything as simple as possible.

Just be careful to use 3V3 instead of 5V or you'll damage your Arduino.

Moreover, keep a finger on the FTDI chip when you connect it the first time.. If there are shorts it will overheat till burning.. so keep an eye on it.



I disconnected both the ADXL345 and the ITG3200 but I left the voltage regulator because from my tests without the voltage regulator the I2C was very unstable.

The logic shifter is also to prevent the 5V signals from the Arduino from affecting the reliability of the sensors (it's important for my project!).

All those components are working fine with the other sensors but they simply don't work for the HMC5843! I checked the connection many times and I'm quite sure there's nothing wrong with it.

Sometimes, the setup sequence does succeed, which I think it's quite indicative of the correct wiring as well!

Bo Xuan

Dude, I know that your circuit is pretty perfect from a theoretical point of view. But if you are having problems it means that there's still something wrong with it. That's why I asked you to remove everything unnecessary. You can plug them back once you figured out what's wrong with it.

Also, are you really sure that your board hasn't the bad capacitor problem?

What kind of application are you up to?


I'm not really sure about the bad capacitor problem. However according to posts I found, the version I have, which has the 4.7uF ceramic cap, it's supposed to work correctly.

I can't exactly prove that with my setup though. I doubt the board will survive any of my attempts to replace that surface mounted capacitor.

Nov 29, 2010, 08:21 pm Last Edit: Nov 29, 2010, 08:24 pm by fax8 Reason: 1
The only thing I can do is showing you how my breakout board looks. I just uploaded a picture to my blog post on first steps with the HMC5843 accuracy verification.

If I remember correctly the older boards have a big black cap..

Anyway, you should give it a try with the simple connection I showed you earlier.



I just tried it, together with a sketch Sparkfun's support sent me. Same errors, NACK on transmit of address..

Bo Xuan


Maybe it's a bad angle in the picture but to me it looks like the board pins are all shorted together because it's plugged into the power strip?
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter



Thanks for replying. It certainly looks like that! But actually I soldered a right angle female header to the board, and it's connected to the breadboard by another right angle male pin header.

Bo Xuan

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131