View previous topic :: View next topic |
Author |
Message |
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
Serial Comms acting screwy |
Posted: Mon Dec 01, 2008 6:49 pm |
|
|
Good day all!
I searched through the forums but I could not find a problem similar to mine. I am doing my second simple comms (RS232) project and trying to receive a simple character via an ASCII modem. I noticed that when you disable DTR on my modem it spits out a "garbage" character. I have also noticed that when my system is first powered up it gets the character everytime, but on a second pass it only gets it once in awhile.
See code below:
Code: |
rx_flag = kbhit();
if (rx_flag == 1)
{
data_in = getc();
if ((data_in == 'r') || (data_in =='R'))
{
delay_us(10);
output_high(RED_LED);
switch_test();
rx_flag=0;
data_in='x';
do
{
switch_test();
}
while ((switch_result == 0) || (switch_result ==1));
output_low(RED_LED);
}
|
I am using kbhit() and getc(), I am wondering if the garbage character sent from the modem is screwing me up? If I power-off everything and power it back on it works fine. I couldn't find a way to "clear" the buffer back to a default state, any ideas or am I missing something simple? My TX strings are working just fine, it's the RX stuff that I am getting hosed on.
I am using a PIC16F690 with CCS C version 4.080.
Any suggestions are greatly appreciated!
Thanks all.
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 01, 2008 7:13 pm |
|
|
You didn't show your #use rs232() statement. Add the ERRORS
parameter to it. (I assume you are using the hardware UART). |
|
|
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
|
Posted: Mon Dec 01, 2008 7:41 pm |
|
|
Thank you for your response, see code below:
Code: |
// Setup RS232 Port.
#use rs232(baud=19200, xmit=PIN_B7, rcv=PIN_B5)
|
If I understand correctly, this will save "error" messages in the variable "RS232_ERRORS" and reset them (according to the manual). What exactly is "reset" them mean?
Thanks for your help.
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 01, 2008 7:43 pm |
|
|
The ERRORS directive tells the compiler to insert additional code so that
any UART overrun errors will be automatically reset. This prevents the
UART from locking up. It only works with the hardware UART (and it's
only needed for the hardware UART). |
|
|
|