CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Serial Comms acting screwy

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Steve_Kos



Joined: 06 Sep 2006
Posts: 12

View user's profile Send private message

Serial Comms acting screwy
PostPosted: Mon Dec 01, 2008 6:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 7:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 7:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 7:43 pm     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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