View Full Version : Serout Using Binary Values

Gary D.
07-27-2005, 11:45 PM
·· I am working on an ecryption project... and have hit a little speed bump.

Here is the scenario. i am trying to send Binary data from 0 to 1024 using the serout command. baud is not important at this time. not familiar with parity bit nor the polarity bit. if it helps this data will·NOT be received by·another Stamp nor Computer.. It will be received on a Binary Decoder Chip for my project.·would this be easier using Shiftout...

I·just want to send the Binary data and perhaps loop every value··4 or·5 times so that it definitely gets·transmitted.

SEROUT·tpin,baud, ....... then im lost

thanks for all feedback...

There are 10 kinds of people....

Those who know binary and those who Don't.

Chris Savage
07-28-2005, 12:13 AM

·· Because you're trying to send a number larger than 255, you will need to send it as two bytes, as in lowbyte then highbyte.· Is the receiving end going to be able to handle a 2 byte value?

SEROUT tpin, baud, [wordVal.LOWBYTE, wordVal.HIGHBYTE]

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Gary D.
07-28-2005, 02:16 AM
Its actually 12 bits ~ 1 1/2 bytes but i guess you can use the High and low byte method. And Yes, the receiver will be able to implement the 2 byte values...

Next Step is to Increment the 12 bits of data... so in actuality i must start from 0 and end at 4095.

i am unfamiliar with the "Wordval" function...

Thanks for your feedback.

There are 10 kinds of people....

Those who know binary and those who Don't.

Paul Baker
07-28-2005, 02:59 AM
wordVal is simply the name he chose to call the variable, if you are refering to the HIGHBYTE/LOWBYTE modifier, they are used to specify a subsection of the variable, refer to the Stamp Manual's pages 87-88 for more discussion.

If your receiver can receive 12 bit values you can probably use something like:

SEROUT tpin, baud, [wordVal.LOWBYTE, wordVal.HIGHBYTE.LOWNIB]

which should send 12 bits of data. As far as incrementing the 12 bit value, just increment the 16 bit variable wordVal. If you need bounds checking (making sure the value does not exceed 4095) simply do a

IF (wordVal > 4095) THEN wordVal = 0 ENDIF

Though if you send the data in a 12 bit quantity, like I showed above, and you dont need to use the 4 bits left over for some other variable, you do not need to do the boundry checking because when you send the lower 12 bits of the 16 bit value, 4096 will be sent as 0 since the 13th bit isn't transmitted.


Post Edited (Paul Baker) : 7/27/2005 8:08:11 PM GMT

Gary D.
07-28-2005, 04:48 AM
Thanks A lot,

I will give this a try and see how it goes...

There are 10 kinds of people....

Those who know binary and those who Don't.

Philip Gamblin
07-29-2005, 11:31 PM
great signature.

07-31-2005, 03:55 AM
Yes, if you are actually using a Binary Decoder, then you should probably send this using a SHIFTOUT command.

SEROUT encodes each byte as an RS232 byte -- with a start bit, level change for each of 8 data bits, maybe a parity bit, and then a stop bit as the line goes back to 'idle'. You'll have to sample the data at exactly the baud rate to get each bit.

SHIFTOUT also sends a shift clock with the data, and will send 16 bits at a time (or 12 bits at a time, with the "\12" modifier). This is much closer to the 'raw serial' your binary decode probably wants to recieve.