BS2 Word/16 Bit Communication

    Jul 18 2006 | 3:00 pm
    Hi everyone,
    I'm trying to get a BS2SX talking with MAXMsp's serial object using Word sized variables. So far I can communicate just fine using any numbers below 255 (byte sized) but after that it gets a bit messy. I realized that I should send over the word variable as a HIGHBYTE and a LOWBYTE and have MAXMsp shift the Highbyte and then add them together.
    This seems to *want* to work, but MAXMsp appears to get off track when taking in the numbers as the HIGHBYTE and LOWBYTE values appear to erratically swap places. I'm trying to find a good method to get consistent and clean input and separation of the two byte's.
    I've tried having MAX send a single ASCII character out to the stamp when it's ready to get the next byte, the problem there is how to I only want to get a bang from the serial object when it receives input. As of right now it passes bangs from the metro right through, which makes it impossible to have MAX send out a new character only when it receives input.
    Thoughts and suggestions?

    • Jul 18 2006 | 3:44 pm
      check out the serial examples with Max on Tom Igoe's Physical Computing pages.
      i found his web pages (and his book) to be the best resources for getting micro controllers to play nice with the Max serial object. (though i use midi now 'cause [serial] is too unstable for live performance...)
    • Jul 18 2006 | 4:55 pm
      Thanks for your link langdon. I had been to his page prior but your re-link made me look closer at his BS2 code. I've been wrestling with this for the better part of a week and finally got it working this morning. The simplicity of my final patch made me smack my head against the desk. You should've seen my patches before...there was tons of stuff about bi-directional communication and Gswitches to direct the different was a mess. I'll post my bs2 code and the patch for anyone who needs large number support.
      BS2(sx) Code:
      ' {$STAMP BS2sx} ' {$PBASIC 2.5} ' {$PORT COM4}
      SerInData VAR Byte 'number to match to incoming data SerWait CON 1000 'ms to wait for input before timing out N9600 CON 240 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400 'See SEROUT in the Basic Stamp manual for details.
      RCvar VAR Word
      Main: HIGH 8 PAUSE 1 RCTIME 8,1,RCvar
      SERIN 16,N9600,SerWait,Main,[SerInData] SEROUT 16,N9600,[RCvar.HIGHBYTE, RCvar.LOWBYTE] GOTO Main
      MAXMsp (4.5.7) patch: