Shop OBEX P1 Docs P2 Docs Learn Events
Serout formatting — Parallax Forums

Serout formatting

alnajjar1alnajjar1 Posts: 110
edited 2011-03-09 18:58 in BASIC Stamp
I am interfacing to a serial device (solid state audio player) and I can communicate directly with it via HyperTerminal with no problem. I attached the short documentation on how to connect the device for reference. Then, I connect the BS2 with same configuration as I use in HT and with the code below. I don't get anything. My cable is good and again, this works fine directly from the PC. I am guessing that I am doing something wrong with formating the data out especially with the binary code and the "software handshaking" requirement.

Any thoughts/help will be most appreciated


' {$STAMP BS2}
' {$PBASIC 2.5}

srOut PIN 1
srIN PIN 0

sData VAR Byte

SEROUT srOut,16468,["A"]
PAUSE 10
SEROUT srOut,16468,[BIN2 01]
PAUSE 10
SERIN srIn,16468,[sData]
DEBUG ? sData
SEROUT srOut,16468,["F"]
PAUSE 10
SERIN srIn,16468,[sData]
DEBUG ? sData
SEROUT srOut,16468,["0"]
PAUSE 10
SERIN srIn,16468,[sData]
DEBUG ? sData
SEROUT srOut,16468,["0"]
PAUSE 10
SERIN srIn,16468,[sData]
DEBUG ? sData
SEROUT srOut,16468,["1"]
PAUSE 10
SERIN srIn,16468,[sData]
DEBUG ? sData
END

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-09 13:19
    For a start, the 2nd SEROUT should look like: SEROUT srOut,16468,[$01]
    This outputs a single byte with the value 1 which is what the EM3028B document describes.

    You should leave out all the PAUSE 10 statements. The program will wait until it receives the acknowledgment character with the SERIN.

    Remember that the DEBUG statements take a few ms to execute. That shouldn't matter in your case since you put them after the SERINs and before the SEROUTs and the EM3028B should be waiting for the next character there.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-09 13:25
    You do need a resistor in series between the BS2 and the RS232 output from the audio player (pin 3).

    This is normally something like 22K. See the Basic Stamp Syntax and Reference Manual sections on SERIN and SEROUT for details.
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-03-09 14:51
    Great!

    I do have 1k resistors at both Rx and Tx lines. Is that enough?

    It isn't clear to me whether or not I have to receive the confirmation bytes back from the device in order to do the 2nd serout or just wait the appropriate amount of time. Does receiving the "handshaking" byte actually clear the buffer or something like that? I am concerned that sending the sequence will take a few seconds which is not an efficient way of communicating with the device. I am trying to trigger a sequence of sound in rapid succession.

    many thanks as always Mike...

    Al
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-09 15:10
    1K is not enough. The problem is that RS232 allows voltages as high as +15V or as low as -15V. More commonly the voltages are lower, but you can't count on it and the resistor has to be large enough to protect the Stamp input pin. Don't use a resistor between the RS232 input and Stamp output or, at least, keep it small (like 1K).

    It's better to receive the confirmation byte. This will take at best 1ms, longer if the music player is slow. A PAUSE is fixed in length. Remember to take out the DEBUG statements. They take time (about 1ms per character) even if there's no debug window open or no PC connected.

    There is no buffer on the Stamp side.
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-03-09 18:58
    Got it! Thanks again. Al
Sign In or Register to comment.