Shop OBEX P1 Docs P2 Docs Learn Events
Serial communication — Parallax Forums

Serial communication

MeepoMeepo Posts: 24
edited 2007-02-28 19:19 in BASIC Stamp
I'm trying to read 4-byte packets from a serial line. These are TTL-level signals sent by another stamp. I'd like to be able to do other tasks while waiting for the bytes. Right now, if someone could just help me with the basics, reading 4 bytes & displaying the decimal values with DEBUG, I'd be all set...

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-28 15:27
    Meepo,

    The BASIC Stamp does not have a FIFO Buffer so you won’t be able to do other tasks while waiting for the bytes. The closest you could come would be to implement handshaking so the BASIC Stamps only communicate when ready. As for the serial example, please see the BASIC Stamp Manual or the Help File under the SERIN/SEROUT commands. There is an example under both commands for connecting two BASIC Stamps together and sending data. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-28 15:33
    The reading 4 bytes and displaying them is easy:
    myBytes var byte(4)
    SERIN <pin>,<Baud>,[noparse][[/noparse]str myBytes\4]
    DEBUG DEC myBytes(0),DEC myBytes(1),DEC myBytes(2),DEC myBytes(3)
    
    


    Your other comment "do other tasks while waiting" may be a problem. The Stamp can only do one thing at a time. If it's doing other tasks, it won't be listening to the serial line and will miss data being sent. You could use some other I/O pins for an "interrupt" and acknowledgment where the other Stamp sets one line to HIGH to indicate that it has data. In between the "other tasks", the second Stamp can check this line and, if it's high, it can set the acknowledge line to HIGH to indicate that it is listening (and immediately do a SERIN). The first Stamp would then set its "interrupt" line to LOW and send the data. The second stamp would set its acknowledge line to LOW and go back to its "other tasks".
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-28 19:19
    Or you could add the "Simple Multi-Tasking" co-processor from this site: http://www.rhombus-tek.com/co-processors.html

    This will give you a simple buffered serial input port, that you can then read with a SHIFTIN when data is ready.
Sign In or Register to comment.