Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 20th October 2009, 01:10 PM   #31
Default

ahm,nope,but we are using the same specs of electronic compass ..



here is the link

http://www.e-gizmo.com/KIT/images/Co...%20Compass.pdf
skidd10 is offline  
Old 23rd October 2009, 05:49 PM   #32
Default

sir rob,
.at least i can base my code with yours.please share your knowledge my mentor.
thanks!
skidd10 is offline  
Old 28th October 2009, 09:33 AM   #33
Default

Skidd10,
Sorry for the delay. Here is some code (not very good) that I use to get the compass heading from the byte stream


unsigned char cReceived=0;

// Then, whilst in the main loop, poll for uart receive
if(U1STAT0 & 0x80) // There is receive data available
{
cCompassByte = U1RXD;// Get received byte
CompassReceive(cCompassByte); // Do something with character received
}

// Here, I want to
//================================================== =====
void CompassReceive(unsigned char ch)
//================================================== =====
{
// Look for $ - frame started
if(ch==0x24)
{
cReceived = 1;
c1=ch;
cReceived++;
return;
}

if(ch)
{
if(cReceived==2)
c2 = ch;
else if(cReceived==3)
c3 = ch;
else if(cReceived==4) // This will be hundreds
cHeading[0] = ch;
else if(cReceived==5) // This will be tens
cHeading[1] = ch;
else if(cReceived==6) // This will be the units
{
cHeading[2] = ch;
nHeading = atoi(&cHeading[0]); //convert to integer
}
else if(cReceived==7)
c7 = ch;
else if(cReceived==8)
c8 = ch;
else if(cReceived==9)
c9 = ch;
else if(cReceived==10)
c10 = ch;
else if(cReceived==11)
{
c11 = ch;
cReceived = 0;
return;
}
else {}

cReceived++;
}
}
robmitch is offline  
Old 28th October 2009, 12:37 PM   #34
Default

ahm,sir rob,
i think u havent included the initiallization?can you share sir the whole code.
thanks for the sample code!
skidd10 is offline  
Old 5th November 2009, 01:51 AM   #35
Default

sir rob,how do you connect the compass to uart0 to uart1?
skidd10 is offline  
Old 5th November 2009, 01:45 PM   #36
Default

if(ch) ======>>>>>sir rob,what is our condition here?
{
if(cReceived==2)
c2 = ch;
else if(cReceived==3)
c3 = ch;
else if(cReceived==4) // This will be hundreds
cHeading[0] = ch;
else if(cReceived==5) // This will be tens
cHeading[1] = ch;
else if(cReceived==6) // This will be the units
skidd10 is offline  
Old 13th November 2009, 02:46 AM   #37
Default

skidd10,
You will have to look up your mcu manual for setting up/initiallising uart with whatever baud rate etc that your compass module has. Other than that, simple wire the compass tx/rx pins to the mcu tx/rx pins, but not necessarily in that order.

if(ch) tests if ch != 0x00 (I put this in since the uart initially sends a 0x00 on startup)

You will be able to make the code much better than this - I was just trying to spell things out.
Cheers,
Rob
robmitch is offline  
Reply

Tags
problems, receive, uart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
PIC 16F877 UART receive yueying_53 Micro Controllers 0 19th October 2008 08:52 AM
How can I Transmit/ Receive BCD noman_dk Electronic Projects Design/Ideas/Reviews 3 23rd February 2008 05:59 PM
Receive data via SPI Sam Jelfs Micro Controllers 2 11th April 2007 06:33 AM
receive data from other pic janetsmith2000@yahoo.com Micro Controllers 1 24th March 2004 07:28 PM
receive 0 data from UART..... wingbar General Electronics Chat 5 15th March 2004 07:11 PM



All times are GMT. The time now is 09:09 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker