SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By m1tch37
#85152
Could you please share your Arduino code? I am also having issues, and it would be good to be able to rule out my code as the problem. Thanks alot.
By Etienne
#85175
Hi,

If somebody have a chip which works, can you post pictures of the data x,y,z when you turn the magnetometer on 360° when it's horizontal and the same when you rotate it on an other axis.

Thanks

Etienne
By sebmadgwick
#86327
I cannot get my HMC5843 to ACK. I have reduced the code and operations to the bare minimum yet I cannot find fault.

- My HMC5843 was purchased last week (i.e. new batch, RE: ESR issues of previous posts).
- dsPIC33FJ64MC804 (~30MIPs), I2C clock 100KHz, pull-ups = 3.3kOhm
- C30 compiler, NOT using I2C library
- code [below] executes every 1ms
Code: Select all
	I2C1CONbits.SEN = 1;		// start I2C
	while (I2C1CONbits.SEN);	// wait for start to complete

	_MI2C1IF = 0;				// clear IF
	I2C1TRN = 0x3D;				// read from HMC
	while(!_MI2C1IF);			// wait for 9th clock edge to end
	_MI2C1IF = 0;				// clear IF

	I2C1CONbits.PEN = 1;		// stop I2C
	while (I2C1CONbits.PEN);	// wait for stop to complete
Which results in the correct master behaviour:

Image

If anyone could please give me feedback / advice / guidance; I do not see any reason why the HMC5843 fails to ACK.
By kushlik
#86646
Hello,

I thought I'd post my findings too. I just got my HMC5843 a few days ago and cannot get it to work. I have the following set up:

- Arduino Mega (Atmega 1280 chip)
- using built-in 10K pullups to 5V (not 3.3V) -- seems to work!!
- 3.3V power to the HMC chip
- 100Khz I2C operation
- avr-gcc compiler
- tried code posted on unit's page on sparkfun, tried code written for HMC5843 (interrupt-based), and tried writing the routines myself with the same result.


The results i am seeing:
- I am able to talk to the chip and get ACKs, etc
- I am able to set the mode and verify that it by reading the registers (although sending a stop condition seems to reset it back to 01). Basically if I set the mode and read it the following way, I can verify it being set:

- Send start condition
- Send SLA+W
- Write two bytes (0x02, 0x00) (set to continuous mode)
- Send repeated start
- Send SLA+W
- Write one byte (0x02) (this resents the data pointer inside HMC)
- Send SLA+R
- Read and NACK one byte

This way, i can see that 0x02 byte (mode) was set to 0x00 (continuous mode). But if I send a stop conditions after setting the mode and then request the value, it is reset to 0x01 !!

I can also read the status (always 0x04) the following way:

- Send start condition
- Send SLA+W
- Write two bytes (0x02, 0x00) (set to continuous mode)
- Send repeated start
- Send SLA+W
- Write one byte (0x09) (this resents the data pointer inside HMC)
- Send SLA+R
- Read and NACK one byte

If i try to read the values (using any one of the three pieces of code) I get something like 0x00 0x20 0x00 0x20 0x00 0x20 or 0x00 0x20 0xff 0xff 0xff 0xff (or some combinations of 0xff and 0x20). The SF code (unmodified) prints out "x=32, y=-1, z=-1), which is equivalent to
0x00 0x20 0xff 0xff 0xff 0xff, which I have seen using my code.

I have seen the comments regarding the cap - I have tried replacing it with 680uF electrolytic with no change. DVDD seems to be ok, though I will look at it on a better scope.

It seems that the problem is in the I2C protocol implementation inside the chip. I think I will try ordering the chip from directly and see what happens. Has anyone tried talking to sparkfun reps about this??
By UhClem
#86700
kushlik wrote:
I have seen the comments regarding the cap - I have tried replacing it with 680uF electrolytic with no change. DVDD seems to be ok, though I will look at it on a better scope.
What is the ESR of that electrolytic cap? Very low ESR is very important.
By kushlik
#86712
A different electrolytic capacitor solved the problem (25uF - don't know the resistance). I also had put in a 1uF tantalum in parallel, so the combination seems to work. Here is a picture of the original issue: VDD line gets pulled down during measurement, apparently causing the chip to reset.

Image

Sparkfun, change those caps!!!
By sebmadgwick
#87365
Is anyone observing the repeatability of the ACK behavior of their HMC5843?

I have found that, if I send a three-byte packet (start+write+reg+value+stop) every 1ms, the HMC will not ACK every ~15th packet. It does this in 'continuous measurement' and 'single measurement' modes, but DOES NOT do it in 'sleep' and 'idle' modes (it ACKs every packet in sleep mode).

I have changed the 'Minimum Data Output Rate' of the sensor to 0.1Hz and 50Hz but this does not change the frequency of failed ACK packets (every 15th packet is still NACK). If a send my packet every 10ms or every 100ms packets are still NACK but not a a visibly constant frequency.

Has anyone else noticed this? Does anyone know somewhere where this is mentioned or discussed? If there are periods when the HMC5843 will ignore I2C activity, we need to know about it!
By sebmadgwick
#87377
Solved the failed ACK problem. and guess what... the capacitor was the problem.

When I use the breakout aboard un-modified, I get the problem described in my previous post. When I touch the legs of my through-hole capacitor* against the pads of the on-board caps, every command is ACK.

*cap = the first 100uF electrolytic I found, ESR unknown.
By planius
#88244
Got my Sparkfun HMC5843 breakout board for Christmas. Connected it with 4.7k pull-up resistors to my STM32F103RB6 board. Same problem as many others - No ACK from the HMC5843 after the first write.

Did what others suggested - grabbed the first best electrolytic capacitor > 10uF from the cupboard, happened to be 33uF/16V. Clipped it over the pads of the capacitor on the breakout board and bang - it works!

When is Sparkfun going to fix this? Why do they keep selling a board that doesn't work?

Not impressed... :evil:
By tz
#90677
(crosspost)
digikey PCC2395CT-ND

Panasonic ECG 10uF 6.3VX5R 0603.

Tiny and the thing makes it work well.

I should also note that the earlier electrolytic 47uF would run for several minutes but stop. This one has been going for a half hour with no signs of stopping.
By PHOLAN
#91904
I just made a post in this same forum with some readings.
Let me know if you have any questions
By asilloo
#93112
Hej,

My project is HMC5843 with Arduino (using HMC file) , but I have a problem, my result as below;

x:4128 y:256 z:8192
x:5119 y:-1 z:-1
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8256
x:4128 y:256 z:8192
x:4129 y:-1 z:-1
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192

these results changing without doing anything and when I try to change the position of the magnetic item around the sensor its not affected. Maybe I did it in wrong way. I don’t know ?. :(

here the video and photo;
http://img37.imageshack.us/img37/8246/linneal023.jpg
http://www.youtube.com/watch?v=XOnYtjlksxw
By tz
#93114
The HMC isn't working properly if you are seeing such values.

You might get different results depending on the local magnetic field, but the "arrow" should be about 500, maybe 200 to 1000 (the square root of the sum of the squares of x, y, and z). And they should jitter around 16 counts just from noise.

First, did you fix the capacitor or are you using a different board?

Second, what code are you using to initialize it?

Third, try connecting ONLY the HMC to the arduino in just one hop of wire, just the 4 wires for sda, scl, ground and 3.3v (I hope you aren't using more than 3.3v). Also check the pull-ups on sda and scl if the arduino itself isn't enabling them on the output port. 5k-10k pullups might help.
By asilloo
#93213
Hej,

thank you ("tz") for your advise, my items as below;

1.Arduino ATmega 328
2.Logic Level Converter sku: BOB-08745
3.HMC5843

and I did every thing as the description at this web page (http://eclecti.cc/tag/hmc5843)

This is the code that I used

#include <HMC.h>

void setup()
{
Serial.begin(9600);
delay(5); // The HMC5843 needs 5ms before it will communicate
HMC.init();
}

void loop()
{
int x,y,z;
delay(100); // There will be new values every 100ms
HMC.getValues(&x,&y,&z);
Serial.print("x:");
Serial.print(x);
Serial.print(" y:");
Serial.print(y);
Serial.print(" z:");
Serial.println(z);
}


As you said I connect the HMC5843 to arduino (GND (HMC) to Gnd (arduino), VCC (HMC) to 3V3 (arduino), SDA (HMC) to Analog in 4 (arduino), SCL (HMC) to Analog in 5 (arduino) ) but happened the same thing in different value ;
x:4128 y:258 z:1028
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8207
x:4128 y:256 z:8192
x:4128 y:256 z:16383
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:-1 z:-1
x:4128 y:256 z:8192
x:4128 y:256 z:8192
x:4128 y:256 z:8192

so is there any suggestion, advise or idea that can help me
:( :roll: