CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

HMC6352 Compass Driver

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

HMC6352 Compass Driver
PostPosted: Sat Sep 06, 2008 8:46 pm     Reply with quote

Thought I'll just move the code here as it is ready to use on the pic's.


Code:
#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)

#define HMC6352_I2C_WRITE_ADDRESS 0x42
#define HMC6352_I2C_READ_ADDRESS  0x43
#define HMC6352_GET_DATA_COMMAND 0x41

// Read the compass heading.  This is in units
// of 1/10's of a degree, from 0 to 3599.
int16 HMC6352_read_heading(void)
{
int8 lsb;
int8 msb;

i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);
i2c_write(HMC6352_GET_DATA_COMMAND);
i2c_stop();

delay_ms(7);  // Allow 1 ms extra for safety

i2c_start();
i2c_write(HMC6352_I2C_READ_ADDRESS);
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

return((int16)lsb | ((int16)msb << 8));
}

//===================================
void main()
{
int16 heading;

while(1)
  {
   heading = HMC6352_read_heading();
   printf("Heading in degrees = %lu\n\r", heading/10);
   delay_ms(1000);
  }

}
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Sep 05, 2010 3:08 am     Reply with quote

does this code really run successfully??
i am afraid to try it because the compass module is very expensive in my country
Bisnouk



Joined: 21 Mar 2007
Posts: 14
Location: Avignon - France

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 14, 2010 1:40 am     Reply with quote

The HMC6352 is very easy to use with PIC. I have still 8 Sparkfun modules is my house, I don't use and I sell them.
But it does not have tilt compensation and as it has only two magnetic axes, you cannot use an external tilt sensor. Also, the heading is wrong if the module is not horizontal. For my automotive module, it wasn't the good sensor.

So, I'm using HMC6343 with integrated tilt compensation. The first release was not good, so I waited for one year and at the beginning of 2010 year, it was ok. Honeywell datasheet is a bit poor (and with some mistakes). I spent much time to correct calibration routine but now, it is fully stable.

For example, my automotive module:

_________________
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

PostPosted: Wed Oct 06, 2010 6:15 pm     Reply with quote

Wow.. its sounds good!!!! Good job bisnouk.

Can you share the HMC6343 simple source code??? It will help the other compass module users out there!!!

Best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group