Shop OBEX P1 Docs P2 Docs Learn Events
Ang: Re: [basicstamps] Serial output — Parallax Forums

Ang: Re: [basicstamps] Serial output

ArchiverArchiver Posts: 46,084
edited 2003-11-13 08:12 in General Discussion
Hello Tracy,

Thanks for the help with my serial output problem, it saved me many hours or
even days of work !!

Regards
/Anders

<<< tracy@e... 6/11 7:51 >>>
> >Does anyone know if it's possible to send a serial string of 5 bytes
>>with 1 startbit, 8 databits, 1 even paritybit and 1 stopbit with the
>>BS2 ? The bitrate should be 2400 bps.
>>Is it possible to get 2400 bps by using the low, high or toggle
>>commands and send it bit by bit - or do you have any other
>>suggestion ?
>>
>
> >(The SEROUT command does not support 8 databits + parity bit !!)


The question was how to transmit 8 bits, even parity, which is not
one of the built-in modes for SEROUT. In actually playing with this
a little more on a BS2, I found the following subroutine comes
pretty close to 2400 baud, 417 microseconds per bit, and calculates
the parity and sends out the data least significant bit first (rs232
standard), with a start bit and a stop bit.

'{$STAMP BS2}
'{$PBASIC 2.5}
' word variable wx contains the assembled 11 bits
' right justified, including 8 bits & parity
' the subroutine send2400 adjusts the timing
' using ~~~ operators.

wx VAR Word
wx0 VAR wx.BIT0 ' alias first bit for implied array
mybyte VAR byte ' byte to transmit
i VAR nib ' index


OUTPUT 2
DO
PULSOUT 1,10 ' 'scope trigger
mybyte=$55 ' example value
GOSUB send2400 ' send it over and over
LOOP

send2400:
wx=mybyte
FOR i=0 TO 7
wx.bit8= wx0(i) ^ wx.bit8 ' calculate even parity
NEXT
wx = wx << 1 | 1 ' append start bit on right
wx=wx ^ %11011011011 ' pre-compensate for inversions to follow
OUT2= ~~~wx0(0) ' start bit
OUT2= ~~~wx0(1) ' data bit 0
OUT2= ~~~~wx0(2) ' the ~~~~ or ~~~ pad the time per bit
OUT2= ~~~wx0(3)
OUT2= ~~~wx0(4)
OUT2= ~~~~wx0(5)
OUT2= ~~~wx0(6)
OUT2= ~~~wx0(7)
OUT2= ~~~~wx0(8) ' data bit 7
OUT2= ~~~wx0(9) ' even parity
OUT2= ~~~wx0(10) ' stop bit
RETURN

A suggestion I made in an earlier post, using PULSOUT to pad the
timing, simply takes too long on the BS2. It can't get down to 417
microseconds per bit. It would work for 1200 baud, though!

-- Tracy

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.


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.