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 CCS Technical Support

HMC6352 Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jony john



Joined: 07 Jun 2010
Posts: 4
Location: malaysia

View user's profile Send private message Yahoo Messenger

HMC6352 Problem
PostPosted: Tue Jun 08, 2010 3:02 am     Reply with quote

Hi all, I'm beginner in CCS.
When I download the program below and the result is nothing happen.
I was check the voltage at SDA and SCL pin and it's 4.88V although rotate the sensor.
I not sure the compass sensor is still ok or not. Can anybody help me to ensure the sensor is still work.

Code I have try:
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)msb | ((int16)lsb << 8));
}

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

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

}
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Tue Jun 08, 2010 7:15 am     Reply with quote

This:

Code:

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


should be this:

Code:

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

You want to multiply the msb by 256 and add it to the lsb, not the other way around.
jony john



Joined: 07 Jun 2010
Posts: 4
Location: malaysia

View user's profile Send private message Yahoo Messenger

HMC6352 Problem
PostPosted: Tue Jun 08, 2010 7:57 pm     Reply with quote

I have try follow your suggestion,but still the same result: nothing happen..
i don't know the sensor still ok or not bcause while solder 4 pin on the sensor the temperature is about 250-300 Celsius..how to know the sensor is good function..
zeronix



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

PostPosted: Tue Jun 08, 2010 8:22 pm     Reply with quote

Have you configured the control register? The sensor have who_i_am register? He should send you a fixed result from this last register.
jony john



Joined: 07 Jun 2010
Posts: 4
Location: malaysia

View user's profile Send private message Yahoo Messenger

control register?
PostPosted: Wed Jun 09, 2010 1:06 am     Reply with quote

zeronix : What you talk about, I don't understand what you try to say. Can you explain detail..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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