|
|
View previous topic :: View next topic |
Author |
Message |
chinng Guest
|
RS 232 Problem! Stopbit failure? |
Posted: Wed Mar 18, 2009 10:53 am |
|
|
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
|
|
Posted: Wed Mar 18, 2009 11:04 am |
|
|
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
|
|
Posted: Wed Mar 18, 2009 11:08 am |
|
|
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
|
|
Posted: Wed Mar 18, 2009 11:11 am |
|
|
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
|
|
Posted: Wed Mar 18, 2009 11:34 am |
|
|
Don't know, if CCS C is able to print a character with %s format. According to the C standard, it's incorrect. |
|
|
|
|
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
|