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

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







HMC6352
PostPosted: Mon Feb 09, 2009 11:39 am     Reply with quote

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
.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 09, 2009 12:15 pm     Reply with quote

You are looking at some preliminary code that was an experiment.
Please use the final driver. It's posted in the code library:
http://www.ccsinfo.com/forum/viewtopic.php?t=35914
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