![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #31 |
|
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 | |
| |
| | #32 |
|
sir rob, .at least i can base my code with yours.please share your knowledge my mentor. thanks! | |
| |
| | #33 |
|
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++; } } | |
| |
| | #34 |
|
ahm,sir rob, i think u havent included the initiallization?can you share sir the whole code. thanks for the sample code! | |
| |
| | #35 |
|
sir rob,how do you connect the compass to uart0 to uart1?
| |
| |
| | #36 |
|
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 | |
| |
| | #37 |
|
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 | |
| |
|
| 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 |