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

RS 232 Problem

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



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

RS 232 Problem
PostPosted: Sun Mar 07, 2010 6:56 pm     Reply with quote

Hi Everybody,

I'm on my first RS232 project and I've encountered a strange problem.

I'm using an 18f2321, v 4.104 software, and a pair of National 96176 Driver IC's between two pic's running the same software (except for the debugger code) and a ICD-U64 debugger
Code:
 
#use rs232(uart1, baud = 19200, Enable = EPIN, stream = Remote, DISABLE_INTS)

#use rs232(DEBUGGER, baud = 19200, stream = Debug, DISABLE_INTS)

============================

#INT_RDA
void InputRS232()
   {
   extern char c;
   c = GetC(Remote);
   }

============================

      if (input_state(k_UA)==0)
         {
         #USE RS232(Stream=Remote)
         putc('U');
         
         #USE RS232(Debugger)
         printf("Local Up \r\n");     
 
         UpArrow();
         }
     
      if (input_state(k_DA)==0)
         {                 
         #USE RS232(Stream=Remote)
         putc('D');
         
         #USE RS232(Debugger)
         printf("Local Down \r\n");
         
         DownArrow();
         }

k_UA and k_DA are Up and Down buttons. I want to send a single character, D or U, to the remote and then use the debugger to print a message to the monitor.

The "Local Up" message displays fine.
The "Local Down" message always displays as "DLocal Down", with the 'D' carried over from the above Putc('D") statement.

Typical output from the monitor:
DLocal Down
DLocal Down
DLoal Down
DLocal Down
Local Up
Local Up


(1) Any idea why the "Down Local" message fails, but "Up Local" always works?

(2) I couldn't find anything on how or when to flush the RS232 comm buffer - Is that necessary?

(3) Any idea why there are letters missing roughly 1 in 10 monitor messages? - I have no other active interrupts running and the speed with which I press the button does not effect the error rate. Changing the Baud rate to 1200 does not help.

Thanks, Al
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 07, 2010 8:14 pm     Reply with quote

You're using streams. Put the #use rs232() statements above main().
(Just one statement for each stream).
Then use the fprintf(), fgetc(), and fputc() statements, and put the
appropriate stream ID into those statements. See the manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Mar 07, 2010 10:20 pm     Reply with quote

Hi PCM programmer,

Back to basics time.

When I use the streams as you suggest I have this program:

Code:
#use rs232(uart1, baud = 19200, Enable = EPIN, stream = Remote, DISABLE_INTS)
#use rs232(DEBUGGER, baud = 19200, stream = Debug, DISABLE_INTS)

==================

Void main(void);

==================


#INT_RDA
void InputRS232()
   {
   extern char c;
   c = fgetC(Remote);
   }

===================

if (input_state(k_UA)==0)
         {
         //#USE RS232(Stream=Remote)
         fputc('U', Remote);
         
         //#USE RS232(Debugger)
         fprintf(Debug, "Local Up \r\n");     
 
         UpArrow();
         }
     
      if (input_state(k_DA)==0)
         {                 
         //#USE RS232(Stream=Remote)
         fputc('D', Remote);
         
         //#USE RS232(Debugger)
         fprintf(Debug, "Local Down \r\n");
         
         DownArrow();
         }




The program sends garbage to the debugger monitor.

When I compromise and use stream names for the Remote function and keep the explicit #USE RS232(Debugger) statements, Like this:

Code:


While(1)
      {     
      if (input_state(k_UA)==0)
         {
         //#USE RS232(Stream=Remote)
         fputc('U', Remote);
         
         #USE RS232(Debugger)
         printf("Local Up \r\n");     
 
         UpArrow();
         }
     
      if (input_state(k_DA)==0)
         {                 
         //#USE RS232(Stream=Remote)
         fputc('D', Remote,);
         
         #USE RS232(Debugger)
         printf("Local Down \r\n");
         
         DownArrow();
         }


The program works fine - the extra 'D' issue is solved and the errors in the monitor stream are much less frequent (1 in 50)

Is the second program good enough to use, or is there some bug in the first program that I need to find?

Thanks, Al
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