Shop OBEX P1 Docs P2 Docs Learn Events
Serout Using Binary Values — Parallax Forums

Serout Using Binary Values

Gary D.Gary D. Posts: 37
edited 2005-07-30 20:55 in BASIC Stamp
Hello...
·· 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.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-27 17:13
    Hello,

    ·· 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, [noparse][[/noparse]wordVal.LOWBYTE, wordVal.HIGHBYTE]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Gary D.Gary D. Posts: 37
    edited 2005-07-27 19:16
    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 BakerPaul Baker Posts: 6,351
    edited 2005-07-27 19:59
    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, [noparse][[/noparse]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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 7/27/2005 8:08:11 PM GMT
  • Gary D.Gary D. Posts: 37
    edited 2005-07-27 21:48
    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 GamblinPhilip Gamblin Posts: 202
    edited 2005-07-29 16:31
    great signature.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-07-30 20:55
    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.
Sign In or Register to comment.