| View previous topic :: View next topic |
| Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Jun 08, 2006 7:24 am |
|
|
Hi
This problem is driving me nuts.
Can someone please tell me how to clear the overrun error bit (OERR) and reset the UART?
Thank you in advance.
a. |
|
 |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Thu Jun 08, 2006 8:56 am |
|
|
Did you see ckielstra's post at the top of the 2nd page of this thread?
| Quote: | | If you have the ERRORS directive in the #use RS232 line you can reset the UART overflow bit just by calling getc(). If you want do it manually you can reset the Overrun Error bit (OERR) by clearing bit CREN (and then re-activate the UART again by setting CREN again). |
The pic's datasheet will tell you which SFR contains CREN, and the memory organization section of the datasheet will tell you the address of that SFR. |
|
 |
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Jun 08, 2006 10:02 am |
|
|
Hi Newguy
Yes I saw the post you mention. But I am a newbie at this, so if you could post a code snippet of how to reset the actual bit that I can modify for the PIC16F873 I would appreciate it.
Thank you
a. |
|
 |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Thu Jun 08, 2006 10:36 am |
|
|
Okay. I'm assuming you're using the 16F873A, since I can't find a 16F873 on Microchip's website.
First: go to chapter 10 of the datasheet, specifically page 114 of 234. This page lists what the various bits within the receive status and control register RCSTA do.
You'll find a description of bit 4, CREN (continuous receive enable bit) and bit 1, OERR (overrun error bit). Note what it says about clearing an overrun error - that it can be cleared by clearing CREN.
Now we just have to find where RCSTA is - we need its address. You have to go to chapter 2 of the datasheet (memory organization) to find this information. Specifically, you'll need section 2.2.2 special function registers, found on page 21 of 234.
You'll find that RCSTA is located at address 0x18 within the PIC's memory.
In your program you would do this (near the top of the program):
| Code: | #bit overrun_error = 0x18.1
#bit cr_enable = 0x18.4 |
Somewhere in you code you would test for the overrun error. If that bit is set, you need to clear CREN, then re-enable CREN. Like so:
| Code: | if (overrun_error) {
cr_enable = 0;
cr_enable = 1;
} |
|
|
 |
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Jun 08, 2006 10:47 am |
|
|
Hi Newguy
Thank you! That is exactly what I need.
I will implement your code snippets tomorrow- I hope they will clear up my problem.
I appreciate your help
a. |
|
 |
|