joseph Guest
|
HMC6352 |
Posted: Mon Feb 09, 2009 11:39 am |
|
|
Hello i'm trying to play with a 2axis compas ( HMC6352 + pi 16f877) but it's doesn't work...... I've read every post, forum but i don't understand...
My code :
Code: |
#include <16f877.H>
#fuses XT,NOPROTECT,NOWDT,NOBROWNOUT
#use delay(clock=4000000)
#use i2c(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,errors)
#define HMC6352_I2C_WRITE_ADDRESS 0x42
#define HMC6352_I2C_READ_ADDRESS 0x43
#define HMC6352_GET_DATA_COMMAND 0x41
long heading;
long HMC6352_read_heading(void);
void main()
{
int16 heading;
heading=0;
while(1)
{
heading = HMC6352_read_heading();
printf("Heading in degrees = %lu\n\r",heading/10);
delay_ms(2000);
}
}
//---------------------------------------------
int16 HMC6352_read_heading(void)
{
int8 lsb=0; int8 msb=0;
i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);
i2c_write(HMC6352_GET_DATA_COMMAND); i2c_stop();
delay_ms(10); // Allow 1 ms extra for safety
i2c_start();
i2c_write(HMC6352_I2C_READ_ADDRESS);
msb = i2c_read();
lsb = i2c_read();
i2c_stop();
heading = msb*255 + lsb/10;
heading = ((int16)lsb | ((int16)msb << 8));
}
|
It's seems, that the compas do not understand, on windows hyper terminal i have :
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
Heading in degrees = 2
..... |
|