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

weird reading on hmc6352

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



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

weird reading on hmc6352
PostPosted: Tue May 24, 2011 10:13 am     Reply with quote

I'm using pcm programmer coding to test hmc6352 with pic16f877a to read value from that compass. Reading I get from that compass are this

"|xxxp@@@@```|``p@ppp|||@`@@@@@@@@"

what is the problem ? can anyone help me ?

this the code

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);
  }

}


help me anyone
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 24, 2011 11:04 am     Reply with quote

What value of pullups do you have of the I2C lines ?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 24, 2011 11:29 am     Reply with quote

Where and how are you getting this? Is your example what you get from the
Printf statement on your PC? If it is, and all you get is garbage, you have an
RS232 problem you must solve first and forget about the sensor until it is fixed...

If the RS232 was OK you should at least see:
Code:
Heading in degrees =

_________________
Google and Forum Search are some of your best tools!!!!
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Tue May 24, 2011 1:44 pm     Reply with quote

temtronic = what value of pullups did you mean ? i dont understan

dyeatman = i get from this forum also

http://www.ccsinfo.com/forum/viewtopic.php?t=45123&view=previous

my rs232 is ok because it can display statement but when i program this code , it show that result and nothing happen .
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 24, 2011 1:48 pm     Reply with quote

OK, to be clear, when you run the program it displays the line "Heading in degrees =" on your PC followed by garbage correct?

If that's the case then you need to verify the parameter values being passed
from the int16 HMC6352_read_heading(void) subroutine. The best way to do
this is to assign values to lsb and msb right after the I2C-stop statement to see if they get passed correctly out of the subroutine.

I could outright give you the answer but you can benefit from the
troubleshooting if I help you figure it out.
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Tue May 24, 2011 1:57 pm; edited 1 time in total
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Tue May 24, 2011 1:54 pm     Reply with quote

dyeatman = the problems is the line "heading in degree" not there . seriously , i have don't know what to do right . give me some hint where i can settle this thing ? please
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 24, 2011 2:00 pm     Reply with quote

OK if the line "Heading in degrees=" does not appear you have an RS232
problem. I assume this going to a PC?
- If so, how is the PIC connected to the PC?
- What is between the PIC and PC?
- What are you using for a terminal program on the PC?
_________________
Google and Forum Search are some of your best tools!!!!
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Tue May 24, 2011 2:25 pm     Reply with quote

First I'm using the startup kit bought from bizchip. You can check the item here.
40 pin pic startup kit
http://www.bizchip.com/kits.html

Between pic and pc using a serial port cable.

Last I'm using the hyper terminal for showing result.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 24, 2011 5:23 pm     Reply with quote

I can't find a detailed description but the kit indicates it has an RS232
interface. If that's the case the problem must be the baud rate being off
somehow.

I would first get rid of Hyperterminal and use something else like Teraterm

http://hp.vector.co.jp/authors/VA002416/teraterm.html
_________________
Google and Forum Search are some of your best tools!!!!
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Wed May 25, 2011 12:29 am     Reply with quote

what do you mean by baud rate being off somehow ??? sorry for asking to much .
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed May 25, 2011 8:41 am     Reply with quote

The speed at which the two "talk" to each other is the baud rate. If the
speed (in this case 9600 baud) is not the same, the two cannot understand
each other and you get garbage. The allowed difference between the two
systems can be from 1-2% up to as much as 10% depending on the
systems involved and their tolerance but you want it below 2%.

Have you checked your terminal program to see if it is set to 9600 No Parity,
8 Bits and 1 stop bit? That's is what your PIC is set to currently.
_________________
Google and Forum Search are some of your best tools!!!!
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