BS2sx Serial Comm puzzle??
Archiver
Posts: 46,084
I am using a BS2sx in conjunction with a Visual Basic program
running on my computer. The BS2sx sits on a circuit board I designed
and communicates to the computer via Pin 12 and Pin 13.
Unfortunately I have no handshaking but I don't think that is an
issue.
I have these two lines of code in the following order
SEROUT 12, 240, [noparse][[/noparse]outputData] ' sends to VB
SERIN 13, 240, 1000, NoData, [noparse][[/noparse]inputData] ' reads from VB
The 'inputData' is a Byte variable and when I send a byte from my VB
program to the BS2sx, I sometimes get a correct reading or I get an
incorrect reading. If I send a 5 to the BS2sx, I get back a 5 but
sometimes I get a 65 or an 80. This has been driving me nuts. If I
take out the 'SEROUT' command line, things work fine....
My VB comm port is sending out only one byte and it does so through
a loop. Is it possible that it is sending the data out too fast? I
have slowed the baud rate to 2400 baud and I still get the same
problem. I have double checked the VB code a dozen times. It's
sending out a 5 to the BS2sx but when I read the inputData variable
it is not always a 5.
If anyone has an idea of what may be the problem, I could certainly
use a little help. Thanks in advance.
Kind Regards,
Eric
running on my computer. The BS2sx sits on a circuit board I designed
and communicates to the computer via Pin 12 and Pin 13.
Unfortunately I have no handshaking but I don't think that is an
issue.
I have these two lines of code in the following order
SEROUT 12, 240, [noparse][[/noparse]outputData] ' sends to VB
SERIN 13, 240, 1000, NoData, [noparse][[/noparse]inputData] ' reads from VB
The 'inputData' is a Byte variable and when I send a byte from my VB
program to the BS2sx, I sometimes get a correct reading or I get an
incorrect reading. If I send a 5 to the BS2sx, I get back a 5 but
sometimes I get a 65 or an 80. This has been driving me nuts. If I
take out the 'SEROUT' command line, things work fine....
My VB comm port is sending out only one byte and it does so through
a loop. Is it possible that it is sending the data out too fast? I
have slowed the baud rate to 2400 baud and I still get the same
problem. I have double checked the VB code a dozen times. It's
sending out a 5 to the BS2sx but when I read the inputData variable
it is not always a 5.
If anyone has an idea of what may be the problem, I could certainly
use a little help. Thanks in advance.
Kind Regards,
Eric
Comments
until it reaches the SERIN command, it is NOT
listening for the Byte. Once it reaches the
SERIN, it Starts listening for the byte. If the
byte is half-done before the BS2 reaches the
SERIN command, it will only get half the byte
-- which looks like gibberish.
If you take out the SEROUT, then the BS2 sits
in the SERIN, waiting for the byte, and always
gets the correct start bit.
Solutions:
1. Send a known 'Sync' byte first, then your
data byte. If the BS2 gets the sync byte correctly,
then the data byte will probably be good also.
You'll modify your SERIN to accept two bytes, in
this case.
2. Have the BS2 send out a 'Ready' byte. Have
VB wait for the ready byte, delay 1 mSec (or
simply do a "DoEvents()"), then
send the data byte. This will give the BS2
time to get into the SERIN before VB sends the
Data byte. Your time-out of 1000 mSec on the
BS2 side gives VB a flexible amount of time to
send the data byte in. You'll have to do this
on every byte.
However, you CAN send a
small (1 to 8 byte) 'packet' of bytes, and
have the BS2 put them in a byte array for
later processing.
The good news is, if you can get the BS2
to start its SERIN in time, you should be able
to run at 9600 baud easily, and perhaps 19200.
--- In basicstamps@yahoogroups.com, "Eric Berg" <khufumen@y...> wrote:
> I am using a BS2sx in conjunction with a Visual Basic program
> running on my computer. The BS2sx sits on a circuit board I
designed
> and communicates to the computer via Pin 12 and Pin 13.
> Unfortunately I have no handshaking but I don't think that is an
> issue.
>
> I have these two lines of code in the following order
>
> SEROUT 12, 240, [noparse][[/noparse]outputData] ' sends to VB
> SERIN 13, 240, 1000, NoData, [noparse][[/noparse]inputData] ' reads from VB
>
>
> The 'inputData' is a Byte variable and when I send a byte from my
VB
> program to the BS2sx, I sometimes get a correct reading or I get an
> incorrect reading. If I send a 5 to the BS2sx, I get back a 5 but
> sometimes I get a 65 or an 80. This has been driving me nuts. If I
> take out the 'SEROUT' command line, things work fine....
>
> My VB comm port is sending out only one byte and it does so through
> a loop. Is it possible that it is sending the data out too fast? I
> have slowed the baud rate to 2400 baud and I still get the same
> problem. I have double checked the VB code a dozen times. It's
> sending out a 5 to the BS2sx but when I read the inputData variable
> it is not always a 5.
>
> If anyone has an idea of what may be the problem, I could certainly
> use a little help. Thanks in advance.
>
> Kind Regards,
> Eric
http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv89.pdf
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Eric Berg [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=IclMAdaGAlMr9MhhR5vFKPMvYv8VrGrCpN_eKUY6sIgwf88VUoM3cD2D2lAODxfQFUMNtIIMcqH3c-FE4w]khufumen@y...[/url
Sent: Thursday, April 22, 2004 6:09 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] BS2sx Serial Comm puzzle??
I am using a BS2sx in conjunction with a Visual Basic program
running on my computer. The BS2sx sits on a circuit board I designed
and communicates to the computer via Pin 12 and Pin 13.
Unfortunately I have no handshaking but I don't think that is an
issue.
I have these two lines of code in the following order
SEROUT 12, 240, [noparse][[/noparse]outputData] ' sends to VB
SERIN 13, 240, 1000, NoData, [noparse][[/noparse]inputData] ' reads from VB
The 'inputData' is a Byte variable and when I send a byte from my VB
program to the BS2sx, I sometimes get a correct reading or I get an
incorrect reading. If I send a 5 to the BS2sx, I get back a 5 but
sometimes I get a 65 or an 80. This has been driving me nuts. If I
take out the 'SEROUT' command line, things work fine....
My VB comm port is sending out only one byte and it does so through
a loop. Is it possible that it is sending the data out too fast? I
have slowed the baud rate to 2400 baud and I still get the same
problem. I have double checked the VB code a dozen times. It's
sending out a 5 to the BS2sx but when I read the inputData variable
it is not always a 5.
If anyone has an idea of what may be the problem, I could certainly
use a little help. Thanks in advance.
Kind Regards,
Eric
Problem:
If the BS2 stamp has the following code
DO UNTIL 1 = 2 ' infinite loop
SEROUT 12, 240, [noparse][[/noparse]5] ' sends to VB (serial output on Pin 12)
SERIN 13, 240, 400, NoData, [noparse][[/noparse]inputData] ' reads from VB
DEBUG DEC inputData, CR
NoData:
LOOP
If the VB program is set as follows
' initialize MSComm1 and then ...
Dim Arr() As Byte
Dim Buffer As Variant
Dim aByte As Byte
aByte = 5
DO Until 1 = 2
Arr = aByte
Buffer = Arr
MSComm1.Output = Buffer
LOOP
'*************
The above code is going to give you fluctuating data for the variable
inputData. It will range from 5 to 65 and sometimes 80. It does this
at no matter what baud rate your working at or what delay you put in
SERIN.
THE SOLUTION:
Put a timer in the VB Code and set its interval to 1. This fixed my
problem and everything is working fine. The problem with trying to
send out a ready byte or a stop byte is that ANY byte sent from the
VB program to the BS2 will be prone to jibberishness (new word)
unless there is a timer delay or you have alot of code between the VB
send codes.
' initialize MSComm1 and then do the following
Dim Arr() As Byte
Dim Buffer As Variant
Dim aByte As Byte
Timer1.Enabled = False
TimerFlag = False ' Declare this variable in the declarations
and then in the Timer event set
TimerFlag = True
aByte = 5
DO Until 1 = 2
If Timer1.Enabled = False then
TimerFlag = False
Timer1.Enabled = True
End If
If TimerFlag = True Then
Arr = aByte
Buffer = Arr
MSComm1.Output = Buffer
Timer1.Enabled = False
TimerFlag = False
End If
LOOP
Thanks for all your help. Should you have any questions feel free to
drop me an email.
Kind Regards,
Eric
TO VB from the BS2? It seems to me this is all
you need for synchronicity -- but you don't
show it in your example.
--- In basicstamps@yahoogroups.com, "Eric Berg" <khufumen@y...> wrote:
> Problem fixed.
>
> Problem:
> If the BS2 stamp has the following code
>
> DO UNTIL 1 = 2 ' infinite loop
> SEROUT 12, 240, [noparse][[/noparse]5] ' sends to VB (serial output on Pin 12)
> SERIN 13, 240, 400, NoData, [noparse][[/noparse]inputData] ' reads from VB
> DEBUG DEC inputData, CR
> NoData:
> LOOP
>
> If the VB program is set as follows
>
> ' initialize MSComm1 and then ...
>
> Dim Arr() As Byte
> Dim Buffer As Variant
> Dim aByte As Byte
> aByte = 5
> DO Until 1 = 2
> Arr = aByte
> Buffer = Arr
> MSComm1.Output = Buffer
> LOOP
>
> '*************
>
> The above code is going to give you fluctuating data for the
variable
> inputData. It will range from 5 to 65 and sometimes 80. It does
this
> at no matter what baud rate your working at or what delay you put
in
> SERIN.
>
> THE SOLUTION:
> Put a timer in the VB Code and set its interval to 1. This fixed my
> problem and everything is working fine. The problem with trying to
> send out a ready byte or a stop byte is that ANY byte sent from the
> VB program to the BS2 will be prone to jibberishness (new word)
> unless there is a timer delay or you have alot of code between the
VB
> send codes.
>
> ' initialize MSComm1 and then do the following
>
>
> Dim Arr() As Byte
> Dim Buffer As Variant
> Dim aByte As Byte
>
> Timer1.Enabled = False
> TimerFlag = False ' Declare this variable in the declarations
> and then in the Timer event set
> TimerFlag = True
> aByte = 5
>
> DO Until 1 = 2
> If Timer1.Enabled = False then
> TimerFlag = False
> Timer1.Enabled = True
> End If
>
>
> If TimerFlag = True Then
> Arr = aByte
> Buffer = Arr
> MSComm1.Output = Buffer
> Timer1.Enabled = False
> TimerFlag = False
> End If
>
> LOOP
>
> Thanks for all your help. Should you have any questions feel free
to
> drop me an email.
>
> Kind Regards,
> Eric
set of LEDs on and off. I excluded it from the email
for clarity. The BS2 sends a byte to the VB program
which indicates the state of several onboard sensors
which the VB processes and then determines which LEDs
to turn on and off and sends the 'LED' byte back to
the BS2.
--- Allan Lane <allan.lane@h...> wrote:
> Question: What are you doing with the byte sent
> TO VB from the BS2? It seems to me this is all
> you need for synchronicity -- but you don't
> show it in your example.
>
> --- In basicstamps@yahoogroups.com, "Eric Berg"
> <khufumen@y...> wrote:
> > Problem fixed.
> >
> > Problem:
> > If the BS2 stamp has the following code
> >
> > DO UNTIL 1 = 2 ' infinite loop
> > SEROUT 12, 240, [noparse][[/noparse]5] ' sends to VB (serial
> output on Pin 12)
> > SERIN 13, 240, 400, NoData, [noparse][[/noparse]inputData] ' reads
> from VB
> > DEBUG DEC inputData, CR
> > NoData:
> > LOOP
> >
> > If the VB program is set as follows
> >
> > ' initialize MSComm1 and then ...
> >
> > Dim Arr() As Byte
> > Dim Buffer As Variant
> > Dim aByte As Byte
> > aByte = 5
> > DO Until 1 = 2
> > Arr = aByte
> > Buffer = Arr
> > MSComm1.Output = Buffer
> > LOOP
> >
> > '*************
> >
> > The above code is going to give you fluctuating
> data for the
> variable
> > inputData. It will range from 5 to 65 and
> sometimes 80. It does
> this
> > at no matter what baud rate your working at or
> what delay you put
> in
> > SERIN.
> >
> > THE SOLUTION:
> > Put a timer in the VB Code and set its interval to
> 1. This fixed my
> > problem and everything is working fine. The
> problem with trying to
> > send out a ready byte or a stop byte is that ANY
> byte sent from the
> > VB program to the BS2 will be prone to
> jibberishness (new word)
> > unless there is a timer delay or you have alot of
> code between the
> VB
> > send codes.
> >
> > ' initialize MSComm1 and then do the following
> >
> >
> > Dim Arr() As Byte
> > Dim Buffer As Variant
> > Dim aByte As Byte
> >
> > Timer1.Enabled = False
> > TimerFlag = False ' Declare this variable
> in the declarations
> > and then in the Timer
> event set
> > TimerFlag = True
> > aByte = 5
> >
> > DO Until 1 = 2
> > If Timer1.Enabled = False then
> > TimerFlag = False
> > Timer1.Enabled = True
> > End If
> >
> >
> > If TimerFlag = True Then
> > Arr = aByte
> > Buffer = Arr
> > MSComm1.Output = Buffer
> > Timer1.Enabled = False
> > TimerFlag = False
> > End If
> >
> > LOOP
> >
> > Thanks for all your help. Should you have any
> questions feel free
> to
> > drop me an email.
> >
> > Kind Regards,
> > Eric
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed.
> Text in the Subject and Body of the message will be
> ignored.
>
> Yahoo! Groups Links
>
>
> basicstamps-unsubscribe@yahoogroups.com
>
>
>