Shop OBEX P1 Docs P2 Docs Learn Events
Getting error data or delay when BS2p24 communiates with BS2 — Parallax Forums

Getting error data or delay when BS2p24 communiates with BS2

ttxno1ttxno1 Posts: 5
edited 2007-11-13 18:36 in BASIC Stamp
Hi
I have two Basic Stamp 2 chips, one is BS2, another one is BS2p24. I try to connect both them, and convey three BYTE data from BS2p24 to BS2. When I use command “SENOUT” to output value in the BS2p24, and command “SENIN” to get value in the BS2, BS2 chip usually delays and gets error data from BS2p24. How can I fix this problem? Thanks.
·
Source Code In the BS2p24:
DO
· SEROUT· 1 , 240 , [noparse][[/noparse]A, B, C]
LOOP

·
·
Source Code In the BS2:
DO
Initial:
· ··········· SERIN 0, 84, 20, Initial, [noparse][[/noparse]A, B, C]
LOOP

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-11-13 16:23
    You can send and wait for a character "header" that synchronizes the two serial commands

    For receiving

    Initial:

    SERIN 0,84,20,Initial,[noparse][[/noparse]WAIT("!"),A,B,C]

    and for transmitting

    SEROUT 1,240,[noparse][[/noparse]"!",A,B,C]

    Jeff T.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-11-13 16:23
    DO
          SEROUT  1 , 240 , 3,[noparse][[/noparse]A, B, C]
        LOOP
    
    



    This adds a small pacing delay so that the slower BS2 can keep up. Also the "!" character is a good idea. Can the BS2p send data at any time? Maybe the BS2 needs a longer timeout, more than 20 milliseconds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 11/13/2007 4:29:05 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-13 16:41
    I would also follow the SEROUT with a PAUSE 100 to allow for processing of the data on the receiving side. My guess is you have a DEBUG not shown in your example and that will take time to execute and display the information on the screen. If the sender immediately sends more data you would miss it without the PAUSE.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • metron9metron9 Posts: 1,100
    edited 2007-11-13 18:27
    Another way to signal the sending processor with the least amount of delay time that allows any amount of processing time is using a dedicated pin. The receiving stamp can pull the pin low (or high) to signal it is ready to receive serial data and then reverse the logic level when it has received the data and busy processing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-13 18:36
    Metron is referring to handshaking which is available on any I/O pin using a Flow Control pin. Please see the Help File or BASIC Stamp Manual under the SERIN/SEROUT commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.