HMC5843

Questions on control of serial busses
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

HMC5843

Post by YahooArchive »

I have been working with the ARMexpress(LPC2103) for a while now, but i have
some serious problems interfacing a HMC5843 Magnetometer to it through I2C.
Since the hardware is T2C its quite simple and in software im using the I2CIN
and I2COUT so its fairly simple as well, but i just cant get it to work.

i have to write to a register in the HMC5843 by sending the following bytes:

0x3C
0x02
0x00
(writing 0 into the 2nd register)

to do that i use the following code(i program it all in C):
--------------------
int accepted = 0;
Maginit[0] = 0x02;
Maginit[1] = 0x00;

accepted = I2COUT(13,15,0x3C,2,MagInit);
--------------------
P13 is SDA
P15 is SCK

I have tried every possible thing but i just cant get it too work, is there any
special thing i have to do, or somthing im not getting?. Im having problems
interfacing SPI units as well, but chips with analog interfaces function
flawlessly....

i have used both 900ohm and 4k7ohm pull-up resistors on I2C.
i have tried all 3 I2C speeds as well.
different pins...etc...


hope someone whos had similar problems can help me...

\W



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: HMC5843

Post by YahooArchive »

When I was trying to get my I2C device to work I tested all address to
see which on responded. Note this is basic, so you'll have to convert to C.

dim present as INTEGER
for i = 1 to 254 step 2 # in C (for(int i=1;i<255;i+=2) {}
shortMessage(0)=chr(0)
shortMessage(1)=chr(1)
present = I2COUT (DataPin, ClkPin, i, 2, shortMessage)
wait(10)
if present = 1 then print " i2c device ***"+hex(i)
if present = 1 then exit
next i

I suspect the second value in the array is ignored, since the odd
addresses are asking for input from the chip (READ)

If you don't get a hit, then the device isn't working. Check power pin
on the device.

Jim.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: HMC5843

Post by YahooArchive »

Also that part has onboard pullup resistors, so try it without the
external pullups.

Jim.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: HMC5843

Post by YahooArchive »

I'm sure this is probably another case of these HMC devices that require clock
stretching, as the slave is TOO slow.

The BASIC I2C.bas was NOT written with that in mind, but should be easily
modifiable to have the master wait until the clock line goes high after it
releases it. I don't have any devices that require this, as its pretty unusual,
so I can't test it.

The same is true for the C code,

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: HMC5843

Post by YahooArchive »

thanks jim, i might try that.

I dont think i can remove the pullups because my software hangs if i do, which
is wierd because, as you say, the device has internal pullups.

If its clock stretching thats the issue cant i simply slow down the interfae
speed?, the devices datasheet stats that the '5843 sensor can operate at speeds
up to 400kbps. isn't this fast enough?

Cathleen
Posts: 1
Joined: Fri Oct 31, 2014 9:45 am

Re: HMC5843

Post by Cathleen »

I dont think i can remove the pullups because my software hangs if i do, which
is wierd because, as you say, the device has internal pullups.

If its clock stretching thats the issue cant i simply slow down the interfae
speed?, the devices datasheet stats that the '5843 sensor can operate at speeds
up to 400kbps. isn't this fast enough?
Cathleen

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: HMC5843

Post by olzeke51 »

There was a Danlee58 that was having issues with an AdaFruit display --( see one of the later posts,)
in using I2C - and it covered several salient issues with the protocol and hardware setup.
'
I use Basic, he used C. I2C seems kind of tricky overall - just look at all the posts in the forum group !!!

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: HMC5843

Post by basicchip »

For most i2c it is fairly straight forward, just hook up the right pins and have pullups and have the right address and it usually works.

Now there are a number of i2c devices that are not quite i2c compatible (usually older ones) and these typically have some issue, many times speed related. I believe the HMC5843 is one of those barely compatible devices. I don't happen to have one, so I can't really give direct aid.

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: HMC5843

Post by danlee58 »

Here is the code that I use for the Addafruit display.

I2COUT (26, 29, 0xE0, 9, list4);

I use IO pins 26 & 29, the addafruit address is 0xE0, and I send 9 characters.

I did modify the I2C Shift code in the Bitbang,c module.

char i2c_shift (int sda_pin, int scl_pin, char value) { // returns TRUE when ACK'd
int i;

i=7;
// i2c_stall();
while (i >= 0) {
SET_SCL_LOW; // drive SCL low
i2c_stall();
if (value & (1<<i)) { SET_SDA_HIGH; } // release SDA high
else { SET_SDA_LOW; } // drive SDA low
// REMOVE THIS NEXT ONE FOR 400 KB RATE
// i2c_stall();
SET_SCL_HIGH; // release SCL high
while ((IN1(scl_pin)) ==0); // allow clock stretching
i2c_stall();

i--;

}
SET_SCL_LOW; // drive SCL low
SET_SDA_HIGH; // let SDA float
i2c_stall();
i2c_stall();
SET_SCL_HIGH; // release SCL high

i2c_stall();
i = INx(sda_pin); // check ACK here (save value in i, 0 was ACK'd

i2c_stall();
SET_SCL_LOW; // drive SCL low

//return i==0; // was it ACK'd
return i;
}

Post Reply