Problems with HMC5843

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

Well, the first thing you should try is run some "known to be working code" .. you can get some at: varesano.net - (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.

Hello!

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 varesano.net -

Hello,

Here's mine, sorry about the mess of wires.
http://www.flickr.com/photos/12634034@N02/5218350450/

Bo Xuan

This looks overcomplicated. I'm connecting the HMC5843 directly to Arduino basically using these connections varesano.net - (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.

Hi,

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.

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.

Hello,

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?

Hi,

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

Bo, I'm sorry but I don't know what else to suggest..

I would suggest asking for a replacement board or get in touch with the support of Sparkfun and ask them if they could help you.

That's real unfortunate. I guess many things are simply beyond prediction (like how I spent 3 weeks on the I2C when it should have taken no more than 3 days). Thanks anyway!

Anyway, I'm still hoping someone else can suggest a solution! Please help!

It might help a little if you had a schematic we could look at. Here are a few more suggestions:

First off if you are using external pullup resistors on the I2C bus you can probably remove them for 2 reasons: 1. according to the datasheet the HMC5843 has internal pullup resistors and 2. if you are using the Sparkfun logic level converter, the active channel (the Tx channel with the MOSFET) is designed with a pullup resistor on the board. So technically if you are using an external pullup you're actually using 3 pullup resistors on the SDA line.

Next if you are using the Rx and Tx lines off one channel of the Sparkfun Logic Level Converter try switching the SCL line to the Tx on the second channel of the converter board and remove that pullup resistor also. Basically what you are doing is using the active bi-directional channels for communication instead of just the resistor divider on the Rx side.

Finally it goes without saying, remove the other sensors from the circuit until you get the HMC5843 working correctly.

Good luck! :slight_smile:

Sparkfun sent me a sketch they use to test the board, together with some suggestions to change some parts of the circuit. I tried all of them and still NACK on transmit of address.

Wayneft, I also tried removing the external pullups, but I got the exact same thing. Without them, my other sensors don't work at all though!

I used both the TX lines on the logic shifter because I2C requires the lines to be bidirectional. I think using just the RX line for either SDA or SCL will cause the I2C to stop working.

Finally, Sparkfun reckons it might be a defective board. But I'll continue testing until the replacement arrives!

yeah, keep us posted..