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

RS 232 Problem! Stopbit failure?

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







RS 232 Problem! Stopbit failure?
PostPosted: Wed Mar 18, 2009 10:53 am     Reply with quote

Hello
I’ve got a problem communicating with a external measure equipment.
Resetting works without problems and if I request data I can see it is sending but I receive nothing useable.
I am using a PIC 18F4550 and the rest is working well.

characteristics from datasheet:

Datarate 4800 Baud
Parity even
Start bit 1
Stop bit 2
ASCII-Code 7 bits ASCII code
Data transmission is followed by <CR> <LF>

Commands
? request data
CLR reset
Followed by <CR>

The RS I initialized as follow
Code:
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, BITS =7, PARITY=E,DISABLE_INTS)


Code:
{
   int c;
   int i=0;
      printf(usb_cdc_putc,"Schieblehre einlesen\r\n");
   putc(63); //?   //ABfragebefehl senden
   putc(13); //\r
   i=0;
   while(!kbhit()&&i<=254) //Warten bis bit in Buffer
      {
      i++;
      delay_us(10);
      }
   while (kbhit())   //solange daten im Buffer
      {
      printf(usb_cdc_putc,"char %S\r\n", getc());   //Daten einlesen und Ausgeben
      }
   return;

}


Anybody a idea what’s is wrong?

Thanks Dominik Brüger
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 11:04 am     Reply with quote

There may be other problems, but your print statement doesn't work for characters. %c would be a correct format.
Code:
printf(usb_cdc_putc,"char %S\r\n", getc());


Also waiting 254*10us may be too short. If no data have been received at this time, the following read step is skipped.


Last edited by FvM on Wed Mar 18, 2009 11:09 am; edited 1 time in total
Ttelmah
Guest







PostPosted: Wed Mar 18, 2009 11:08 am     Reply with quote

What are you meant to receive?.
Your existing code, will potentially just get the very first character. One character arrives, and is echoed out the USB. This takes a few uSec only. The next character, won't arrive for over 2mSec, so you will drop out of your 'while(kbhit)' loop.
FvM, has pointed out that your format is wrong. In fact this will print garbage, since it is expecting to receive a pointer to a string, and you are handing it a character.

Best Wishes
Guest








PostPosted: Wed Mar 18, 2009 11:11 am     Reply with quote

Could you explain me why?
in the help file is written that %s is for String or character and %c is just for a character
thx
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 11:34 am     Reply with quote

Don't know, if CCS C is able to print a character with %s format. According to the C standard, it's incorrect.
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