|
|
View previous topic :: View next topic |
Author |
Message |
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
HMC6352 Compass Driver |
Posted: Sat Sep 06, 2008 8:46 pm |
|
|
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
|
|
Posted: Sun Sep 05, 2010 3:08 am |
|
|
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
|
|
Posted: Tue Sep 14, 2010 1:40 am |
|
|
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
|
|
Posted: Wed Oct 06, 2010 6:15 pm |
|
|
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 |
|
|
|
|
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
|