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 CCS Technical Support

At My Wit's End with RS 232

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



Joined: 27 Sep 2006
Posts: 11
Location: ITHACA,NY

View user's profile Send private message

At My Wit's End with RS 232
PostPosted: Tue Oct 03, 2006 9:05 pm     Reply with quote

Hi,
I'm totally flummoxed and would REALLY appreciate any help on this one.

I am trying to control a microscope stage with the pic via RS232.
When I send the following code, the stage controller responds with an error message. However sending it to the pc instead and recieving the printf command with the serial moniter in the compiler (serial moniter set to baud 9600 databits 8 stp bits 1 parity none) and then sending that same command in hex form from the serial moniter to the controller it works. What the heck! Is there a handshaking problem here? I have no idea why this isn't working. Please Help!

Code:

#include <18F4550.h>   //This header contains chip info.
#include <STDLIB>    //standard C library
#include <math>
#fuses HS,NOLVP,NOWDT,PUT  //fuses on the chip
#use delay (clock=20000000) //this relates the clock speed of the chip for various functions (delay_ms etc)
#use rs232(baud=9600, parity = n, bits = 8, xmit=PIN_C6, rcv=PIN_C7) //load RS232 port

#define BUTTON PIN_A4        //Button on the prototyping board
#define GRE PIN_A5           //These macros define the leds
#define YEL PIN_B4           //On the prototyping board
#define RED PIN_B5           //Which will be used to determine operation states
#define LED_ON output_low
#define LED_OFF output_high

void main(void){

   int8 i = 0;
   int16 timeOut=0;
   char buffer[30];
   char charTest;

   LED_ON(GRE);
   
   printf("MINSPEED 1000\r ");
   while(!kbhit()){}
   do {
      if(kbhit()){
      charTest = getc();
      buffer[i++] = charTest;}
   } while((charTest!=13)&&(timeOut++<10000)&&(i<=29));

   while(1)
   {
     putc(buffer[i++]);
     if(i == 29)
     i = 0;
     delay_ms(500);
   }

}
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 03, 2006 9:18 pm     Reply with quote

I could not understand what you meant in your text but I could read the code :-)

The timeout loop is probably rolling over too quickly. Try this...

Code:

#use rs232(baud=9600, parity = n, bits = 8, xmit=PIN_C6, rcv=PIN_C7, ERRORS) //load RS232 port


and this..

Code:

   while(!kbhit())
      ;
   do {
      if(kbhit()){
      charTest = getc();
      buffer[i++] = charTest;
      timeOut = 0;
      }
   } while((charTest!=13)&&(timeOut++<10000)&&(i<=29));

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 03, 2006 9:23 pm     Reply with quote

If you can't get it working, then post a link to the User's Manual for the
microscope stage, in which it describes the serial protocol in detail.
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