Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

uart receive problems

Status
Not open for further replies.
contacted manufacturer. default baud9600, one stop bit, no parity... which is what i was using. Will try and look with scope, but might take a while to get one to use...
 
contacted manufacturer. default baud9600, one stop bit, no parity... which is what i was using. Will try and look with scope, but might take a while to get one to use...

hi Rob,

If you connect a MAX232 to the Compass output you will be able to use a PC to communicate with the Compass.
 
I have conneced it all up, although when I read rx data, I only get, 00, as well as a framing error and overrun error, after a couple of reads. Also, that was after a lot of coaxing to get it to actually read uart1 instead of the default uart0...

It seems as though there is always one char available at startup (after entering main() ), even with the module unpowered (value also 00). Then, when I power the module, more become available (all 00, as mentioned). I tried in interrupt mode and polling mode.
...

That is a pretty common problem, getting a 0x00 on startup with a framing error, it means something is holding that pin low at startup.

Try putting a delay in your startup code where you set the pin directions, then the delay (this lets the pin voltages settle etc), THEN initialise the UART.

I'm not sure why you get the same problem "after a couple of reads" but I would definitely look at the problem happening at startup first, that might lead to solving the second problem.
 
It's alive! :):) My first microcontroller interface!;)

Thanks guys. I ended up relaying everything from compass on UART1 to hyperterminal via UART0 and its max232. Wasnt getting any readings, and checked connections again... I think they have mis-labelled the rx/tx pins on the compass module, because it works now having swapped the lines - so now they are not crossed-over (rx-rx and tx-tx). Then again, I have been known to get things wrong when it comes to connecting things on the opposite side of a board to the drawing, when a 50/50 chance will get it wrong...

Some output:
Next Reading
$H,109*3A
Next Reading
$H,110*32
Next Reading
$H,110*32
Next Reading
$H,106*35

(Mike, my getChar() routine sent the received char to the hyperterminal, so thats why the $ appears in above readings)

The 109, 110, and 106 are heading degrees

Wow, this site and you guys are awesome. Standby for more problems from me.
Cheers,
Rob
 
engiah,
I am pretty new myself. I havent used a software uart. Maybe someone else here can help you out.
Cheers,
Rob
 
sir robmitch,
can u post ur code on receiving data from the compass?, im also dealing with the same problem about the electronic compass. can i become ur apprentice?!!:D
 
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++;
}
}
 
ahm,sir rob,
i think u havent included the initiallization?can you share sir the whole code.
thanks for the sample code!
 
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,
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top