|
|
View previous topic :: View next topic |
Author |
Message |
theteaman
Joined: 04 Aug 2006 Posts: 98
|
rs232 buffer error |
Posted: Tue Jan 09, 2007 4:37 am |
|
|
Hello
I use two RS232 streams:
Code: |
#use rs232(baud=19200, xmit=PIN_B6, PARITY=N, STREAM=PORT_LCD)
#use rs232(baud=31250, xmit=PIN_C0, PARITY=N, STREAM=PORT_B)
|
These work fine except for one small bug.
When I first turn on my circuit (I use a simple on/off switch) I _occasionally_ get a random byte or two coming through one or both the ports. This is really annoying! For example, when I turn it on the LCD will display a seemingly random character.
I think maybe I need to clear the buffer on the PIC but I don't know how to do this, or even if I am on the right track. Any ideas??
I'm using an 18F2525.
Thanks |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Jan 09, 2007 9:19 am |
|
|
We donīt have enough info regarding your code during the power up nor your hardware
enviroment, but regarding your comments, after power up I would keep disabled
all communications and add a long delay in the very first lines of your code, waiting
for stabilization. After this procedure I would enable the communications.
Quote: |
I think maybe I need to clear the buffer on the PIC but I don't know how to do this, or even if I am on the right track. Any ideas??
|
Lets assume that before using any data of the buffer you must know the if the data
stored in the buffer is valid data or garbage resulting of the power up. It is a good
practice to clear the used RAM space -buffers included- at power up just to put them
in a know state.
This is a tip regarding how you can do it.
Code: |
#define Size_A 20 // Define the size of the buffer A
#define Size_B 42 // Define the size of the buffer B
int Buffer_A[Size_A]; // Reserve RAM for the Buffer_A
int Buffer_B[Size_B]; // Reserve RAM for the Buffer_B
void clear_buffer(int Buffer_name, int Buffer_size)
{
int n;
for( n=0; n<=Buffer_size; n++)
{ Buffer_name[n] = 0; }
}
// Then you can clear any buffer with:
clear_buffer(Buffer_A, Size_A);
clear_buffer(Buffer_B, Size_B);
|
Humberto |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 09, 2007 11:41 am |
|
|
It is very common indeed for spurious characters to be received on both hardware inputs, and software inputs, when booting. Remember that on RS232, the 'idle' state is 'high', and chips like the MAX232 buffers commonly used, take some tme to fully wake up.
Do what Humberto says, and have a delay. Before enabling interrupts, use 'clear_interrupt', and read characters, so that any garbage to this point will be thrown away. To clear the hardware buffer, on the INT_RDA interrupt fo example, have:
Code: |
#byte PIR1=0xF9E //for 18 chips
#bit RDAIF=PIR1.5
while (RDAIF) getc();
enable_interrupts(INT_RDA);
|
With the 'getc', from the stream connected to this interrupt.
Best Wishes |
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Tue Jan 09, 2007 7:02 pm |
|
|
Hello
Thank you very much!
Thanks |
|
|
cap1108784 Guest
|
RS232 issues |
Posted: Tue Feb 17, 2009 10:44 am |
|
|
HI, I am also trying to get the rs232 to work so i can communicate simple bdata to a pc.
You are the first thread I have found that has had some success with rs232 on the 18f2525.
If possible can you post the code so I can see what bits I'm missing.
Thanks
Chris.. |
|
|
|
|
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
|