serial headache again
connected serially. Using port D I have TXD going to RXD, RTS going to
CTS, GND going to GND. (pins PC0 to PC1, PC2 to PC3, etc) All
connections are sound. On Rabbit A I have a continuous loop sending
"HELLO" to Rabbit B. Rabbit B runs through a constant loop reading
port D and printing what it receives to the screen. No matter what I
try it prints the first 2 character (H & E) in a mixed up pattern. It
seems to me I have a timing problem but what do I know. Please help,
before I check myself into the mental ward ;^)
=============
Sending Code:
=============
#class auto
#define DINBUFSIZE 15
#define DOUTBUFSIZE 15
#define SERD_CTS_PORT PCDR
#define SERD_CTS_BIT 3
#define SERD_RTS_PORT PCDR
#define SERD_RTS_SHADOW PCDRShadow
#define SERD_RTS_BIT 2
const char s[] = "Hello";
void main(){
serDopen(19200);
serDflowcontrolOn();
loopinit();
while(1){
costate{
serDwrFlush();
wfd cof_serDputs(s);
}
printf("%s\n",s);
}
serDclose();
}
===============
Receiving Code:
===============
#class auto
#define DINBUFSIZE 63
#define DOUTBUFSIZE 63
#define timeout 20UL
#define SERD_CTS_PORT PCDR
#define SERD_CTS_BIT 3
#define SERD_RTS_PORT PCDR
#define SERD_RTS_SHADOW PCDRShadow
#define SERD_RTS_BIT 2
main() {
int getOk;
char s[16];
serDopen(19200);
serDflowcontrolOn();
loopinit();
while (1) {
loophead();
costate {
wfd getOk = cof_serDgets (s, 15, timeout);
if (getOk)
printf("%s\n",s);
else {
printf(" - FAILED - \n");
}
}
}
serDclose();
} ======
OUTPUT
======
eHHHHHHHHHHHHeH
HHHHHHHHHHHHeHH
HHHHHHHHeHHHHHH
HHHHeHHHHHHHHHe
HHHHHHHHHHHHeHH
HHHHHHHHHHHeHHH
HHHHHHHHHeHHHHH
HHHHHHHeHHHHHHH
HHHHHeHHHHHHHHH
HeHHHHHHHHHHeHH
HHHHHHHHHeHHHHH
HHHHHHHeHHHHHHH
HHHHHHHeHHHHHHH
Thanks in advance,
stujo
I think your problem is with flushing the serial port every time you send something, i.e. you are flushing data that is yet to exit the serial libraries circular buffer (on route to the UART). Just flush it once before you enter your while loop.
Also, serXopen accepts a long, but you are passing it an int (type defaults to int when not defined). Pass 19200L instead.
Nathan
-----Original
Message-----
From: r...@yahoogroups.com
[mailto:r...@yahoogroups.com] On
Behalf Of stujo
Sent: Monday, 1
August 2005 1:24 PM
To: r...@yahoogroups.com
Subject: [rabbit-semi] serial
headache again
Simple task but I make it so
difficult. I have 2 RCM2200 modules
connected serially. Using port D I have TXD going
to RXD, RTS going to
CTS, GND going to GND. (pins PC0 to PC1, PC2 to
PC3, etc) All
connections are sound. On Rabbit A I have a
continuous loop sending
"HELLO" to Rabbit B. Rabbit B runs
through a constant loop reading
port D and printing what it receives to the
screen. No matter what I
try it prints the first 2 character (H & E) in
a mixed up pattern. It
seems to me I have a timing problem but what do I
know. Please help,
before I check myself into the mental ward
;^)
=============
Sending Code:
=============
#class auto
#define DINBUFSIZE 15
#define DOUTBUFSIZE 15
#define SERD_CTS_PORT PCDR
#define SERD_CTS_BIT 3
#define SERD_RTS_PORT PCDR
#define SERD_RTS_SHADOW PCDRShadow
#define SERD_RTS_BIT 2
const char s[] = "Hello";
void main(){
serDopen(19200);
serDflowcontrolOn();
loopinit();
while(1){
costate{
serDwrFlush();
wfd cof_serDputs(s);
}
printf("%s\n",s);
}
serDclose();
}
===============
Receiving Code:
===============
#class auto
#define DINBUFSIZE 63
#define DOUTBUFSIZE 63
#define timeout 20UL
#define SERD_CTS_PORT PCDR
#define SERD_CTS_BIT 3
#define SERD_RTS_PORT PCDR
#define SERD_RTS_SHADOW PCDRShadow
#define SERD_RTS_BIT 2
main() {
int getOk;
char s[16];
serDopen(19200);
serDflowcontrolOn();
loopinit();
while (1) {
loophead();
costate
{
wfd getOk = cof_serDgets (s, 15, timeout);
if (getOk)
printf("%s\n",s);
else {
printf(" - FAILED - \n");
}
}
}
serDclose();
}
======
OUTPUT
======
eHHHHHHHHHHHHeH
HHHHHHHHHHHHeHH
HHHHHHHHeHHHHHH
HHHHeHHHHHHHHHe
HHHHHHHHHHHHeHH
HHHHHHHHHHHeHHH
HHHHHHHHHeHHHHH
HHHHHHHeHHHHHHH
HHHHHeHHHHHHHHH
HeHHHHHHHHHHeHH
HHHHHHHHHeHHHHH
HHHHHHHeHHHHHHH
HHHHHHHeHHHHHHH
Thanks in advance,
stujo
I changed the code as suggested and it works great. Now the answer
only breeds more questions. What needs to be done for a string that
grows or shrinks?
--- In rabbit-semi@rabb..., "Nathan Johnston" <nathanj@d...>
wrote:
> I think your problem is with flushing the serial port every time you
> send something, i.e. you are flushing data that is yet to exit the
> serial libraries circular buffer (on route to the UART). Just flush
it
> once before you enter your while loop.
>
> Also, serXopen accepts a long, but you are passing it an int (type
> defaults to int when not defined). Pass 19200L instead.
>
> Nathan
> =============
> Sending Code:
> =============
> #class auto
> #define DINBUFSIZE 15
> #define DOUTBUFSIZE 15
> #define SERD_CTS_PORT PCDR
> #define SERD_CTS_BIT 3
> #define SERD_RTS_PORT PCDR
> #define SERD_RTS_SHADOW PCDRShadow
> #define SERD_RTS_BIT 2
> const char s[] = "Hello";
> void main(){
> serDopen(19200L);
> serDflowcontrolOn();
> loopinit();
> serDwrFlush();
> while(1){
> costate{
> wfd cof_serDputs(s);
> }
> printf("%s\n",s);
> }
> serDclose();
> }
>
> ===============
> Receiving Code:
> ===============
>
> #class auto
> #define DINBUFSIZE 63
> #define DOUTBUFSIZE 63
> #define timeout 20UL
> #define SERD_CTS_PORT PCDR
> #define SERD_CTS_BIT 3
> #define SERD_RTS_PORT PCDR
> #define SERD_RTS_SHADOW PCDRShadow
> #define SERD_RTS_BIT 2
>
> main() {
> int getOk;
> char s[16];
> serDopen(19200L);
> serDflowcontrolOn();
> loopinit();
> while (1) {
> loophead();
> costate {
> wfd getOk = cof_serDgets (s, 5, timeout);
> if (getOk)
> printf("%s\n",s);
> else {
> printf(" - FAILED - \n");
> }
> }
> }
> serDclose();
> }_______________________
It shouldn’t make a difference. Just make sure your send and receive buffers are large enough (especially the receive side if you are not reading the serial port very fast).
I would advise against ever flushing a serial port write buffer…
Nathan
-----Original
Message-----
From: r...@yahoogroups.com
[mailto:r...@yahoogroups.com] On
Behalf Of stujo
Sent: Monday, 1
August 2005 2:32 PM
To: r...@yahoogroups.com
Subject: [rabbit-semi] Re: serial
headache again
Thanks a million Nathan !!!
I changed the code as suggested and it works
great. Now the answer
only breeds more questions. What needs to be done
for a string that
grows or shrinks?
--- In r...@yahoogroups.com, "Nathan
Johnston" <nathanj@d...>
wrote:
> I think your problem is with flushing the
serial port every time you
> send something, i.e. you are flushing data
that is yet to exit the
> serial libraries circular buffer (on route to
the UART). Just flush
it
> once before you enter your while
loop.
>
> Also, serXopen accepts a long, but you are
passing it an int (type
> defaults to int when not defined). Pass
19200L instead.
>
> Nathan
> =============
> Sending Code:
> =============
> #class auto
> #define DINBUFSIZE 15
> #define DOUTBUFSIZE 15
> #define SERD_CTS_PORT PCDR
> #define SERD_CTS_BIT 3
> #define SERD_RTS_PORT PCDR
> #define SERD_RTS_SHADOW
PCDRShadow
> #define SERD_RTS_BIT 2
> const char s[] =
"Hello";
> void main(){
>
serDopen(19200L);
>
serDflowcontrolOn();
> loopinit();
>
serDwrFlush();
> while(1){
>
costate{
>
wfd cof_serDputs(s);
>
}
>
printf("%s\n",s);
> }
> serDclose();
> }
>
> ===============
> Receiving Code:
> ===============
>
> #class auto
> #define DINBUFSIZE 63
> #define DOUTBUFSIZE 63
> #define timeout 20UL
> #define SERD_CTS_PORT PCDR
> #define SERD_CTS_BIT 3
> #define SERD_RTS_PORT PCDR
> #define SERD_RTS_SHADOW
PCDRShadow
> #define SERD_RTS_BIT 2
>
> main() {
> int getOk;
> char s[16];
>
serDopen(19200L);
>
serDflowcontrolOn();
> loopinit();
> while (1) {
>
loophead();
> costate
{
>
wfd getOk = cof_serDgets (s, 5, timeout);
>
if (getOk)
>
printf("%s\n",s);
>
else {
>
printf(" - FAILED - \n");
>
}
>
}
> }
> serDclose();
> }_______________________
a whole string. You then either need some sort of standard terminating character/phrase or a timeout that
indicates that message is finished. Simplest thing would be a while loop that reads 1 char at a time, storing it until
you reach your termination char... which might be a ':' or '%' or something you would not normally Tx in the
message. Alternatively... there is quite a bit of open source documentation on industrial serial protocols that will
provide you with more idea's on data transmission over serial, though less efficient if all you want to do is
transmit text... Quoting stujo <stujo@stuj...>:
>
> Thanks a million Nathan !!! >
> I changed the code as suggested and it works great. Now the answer
>
> only breeds more questions. What needs to be done for a string that
>
> grows or shrinks? >
> --- In rabbit-semi@rabb..., "Nathan Johnston" <nathanj@d...>
>
> wrote:
>
> > I think your problem is with flushing the serial port every time you
>
> > send something, i.e. you are flushing data that is yet to exit the
>
> > serial libraries circular buffer (on route to the UART). Just flush
>
> it
>
> > once before you enter your while loop.
>
> >
>
> > Also, serXopen accepts a long, but you are passing it an int (type
>
> > defaults to int when not defined). Pass 19200L instead.
>
> >
>
> > Nathan >
> > =============
>
> > Sending Code:
>
> > =============
>
> > #class auto
>
> > #define DINBUFSIZE 15
>
> > #define DOUTBUFSIZE 15
>
> > #define SERD_CTS_PORT PCDR
>
> > #define SERD_CTS_BIT 3
>
> > #define SERD_RTS_PORT PCDR
>
> > #define SERD_RTS_SHADOW PCDRShadow
>
> > #define SERD_RTS_BIT 2
>
> > const char s[] = "Hello";
>
> > void main(){
>
> > serDopen(19200L);
>
> > serDflowcontrolOn();
>
> > loopinit();
>
> > serDwrFlush();
>
> > while(1){
>
> > costate{
>
> > wfd cof_serDputs(s);
>
> > }
>
> > printf("%s\n",s);
>
> > }
>
> > serDclose();
>
> > }
>
> >
>
> > ===============
>
> > Receiving Code:
>
> > ===============
>
> >
>
> > #class auto
>
> > #define DINBUFSIZE 63
>
> > #define DOUTBUFSIZE 63
>
> > #define timeout 20UL
>
> > #define SERD_CTS_PORT PCDR
>
> > #define SERD_CTS_BIT 3
>
> > #define SERD_RTS_PORT PCDR
>
> > #define SERD_RTS_SHADOW PCDRShadow
>
> > #define SERD_RTS_BIT 2
>
> >
>
> > main() {
>
> > int getOk;
>
> > char s[16];
>
> > serDopen(19200L);
>
> > serDflowcontrolOn();
>
> > loopinit();
>
> > while (1) {
>
> > loophead();
>
> > costate {
>
> > wfd getOk = cof_serDgets (s, 5, timeout);
>
> > if (getOk)
>
> > printf("%s\n",s);
>
> > else {
>
> > printf(" - FAILED - \n");
>
> > }
>
> > }
>
> > }
>
> > serDclose();
>
> > }_______________________ > SPONSORED LINKS >
>
> Embedded module > Microcontrollers > Intel microprocessors >
>
> Pic microcontrollers > 8086 microprocessor > 8051 microprocessor >
> YAHOO! GROUPS LINKS >
>
>
add a \n, \r or null caracter at the end of your data you could read
your buffer without use the timeout(With ASCII comunication). If the
time is not a critical variable for your comunications, is very
usefull put some delay for send data using waitfor(DelayMS(XX)) in
your costates.
If you use the constant declaration for the string you must use
pointers, or you could corrupt the memory and send wrong caracters
through your serial port.