View previous topic :: View next topic |
Author |
Message |
jony john
Joined: 07 Jun 2010 Posts: 4 Location: malaysia
|
HMC6352 Problem |
Posted: Tue Jun 08, 2010 3:02 am |
|
|
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
|
|
Posted: Tue Jun 08, 2010 7:15 am |
|
|
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
|
HMC6352 Problem |
Posted: Tue Jun 08, 2010 7:57 pm |
|
|
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
|
|
Posted: Tue Jun 08, 2010 8:22 pm |
|
|
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
|
control register? |
Posted: Wed Jun 09, 2010 1:06 am |
|
|
zeronix : What you talk about, I don't understand what you try to say. Can you explain detail.. |
|
|
|