Shop OBEX P1 Docs P2 Docs Learn Events
Serial input loosing data — Parallax Forums

Serial input loosing data

rdinghamrdingham Posts: 5
edited 2009-01-16 16:14 in BASIC Stamp
I need to setup a BS2 SX to act as a go-between between a PC and a Parralax motor controller. But, my stamp looses data. I have to use the stamp fo the motorcontroller since it's a one wire interface. But the Stamp looses it's protocol synchronization, and I can't figure out why. I have a one second delay between bytes coming from my PC at 4800 baud, so there's no excuse for the stamp to not be ready for the next byte.

I'm stumped.

Comments

  • remmi870remmi870 Posts: 79
    edited 2009-01-14 07:52
    it is posable that the stamp just isnt fast enough to recive the data, not to mention that it might be missing a byte and so your data is being ofsett and lost.
  • stamptrolstamptrol Posts: 1,731
    edited 2009-01-14 13:34
    The BS2sx is very capable at 4800 baud.

    Attach your code so we can make some suggestions. As long as the Stamp is waiting for the byte when it occurs, theres no reason it won't grab it.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • rdinghamrdingham Posts: 5
    edited 2009-01-15 04:42
    Here's my program. I'm testing currently at 4800 baud and a one second delay between bytes writing them from the PC, so I can't see any excuse for a byte to get lost. There should be oodles of time for the stamp to be ready for the next byte. That's why I think I must be doing something else wrong.

    Program code should be attached, it I didn't mess that up too.

    Should the ports be set as output, and HIGH or LOW by default?

    Should I have pull up or pull down resistors on them?

    I really appreciate any guidance. Thanks.
  • rdinghamrdingham Posts: 5
    edited 2009-01-15 06:16
    Maybe I'd better try to explain the problem I'm trying to solve, and the hardware and software I'm trying to do it with.

    Problem:

    I want to interface a Parralax "Motor Mount & Wheel Kit with Position Controller" to a PC based serial port. The Parralax position controller uses a single pin for both receive and transmit 5V rs232 @ 19200 baud. Since a PC can not use the same pin for TX and RX, I need an interface controller. The Parralax "Position Controller" is explicitly designed to be able to interface through a Basic Stamp.

    Solution:

    I have a Parralax Board of Education (BOE) board with a BS2 SX. It may be an original since I don't see a REV. ID on it. I want to use either its I/O pins for input from a PC or it's USART dedicated serial pins.

    I wrote a Java driver module (class) to drive the Position Controler through a PC serial port. PC's use a minimum three wire interface (Gnd, Tx, Rx).

    I wrote a Java module to emulate the Parralax "Position Controller" through the PC serial port for testing the control module.

    When I connect the two serial ports together in a NULL Modem arrangement, The two modules and a test program work correctly. I intend to use this to test the Basic Stamp 2SX program.

    My serial interfaces on the PC are FT232R USB-to-Serial converters. Their voltage levels are 3.3V based. My assumption is that this is sufficiently compatible with the 5V based pins of the Basic Stamp 2SX.

    This interface is the first step in building my PC Laptop based robot platform. I am struggling with getting this very first hardware interface working so that it can move around.

    Seems to me like this would be a great sample project for Parralax to have posted somewhere as Examples.
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2009-01-15 10:23
    your stamp loses protocol synchronization because there is no protocol. This is what you should establish.
    Remember that the stamp isn't always ready to receive and the communication is unbuffered. You could provide
    a hardware buffer or handle the situation using a protocol:
    1) let the stamp wait for some synch character leading your command string (check the stamp manual about this).
    2) receive and interpret your command string and execute the command on the stamp
    3) send an acknowledgment string or character back to the host when the stamp is supposed to be ready
    to receive the next command (provided the host's comm port is buffered which is usually the case).
    regards
    adrian
  • rdinghamrdingham Posts: 5
    edited 2009-01-16 06:11
    The protocol is the protocol of the Parralax motor position controller. One command byte followed by zero to two parameter bytes based on the command code. Then, depending on the command code zero to two response bytes are sent back.

    Since I am waiting about a second between bytes at the PC side, there is no excuse for the stamp not to be waiting for the next byte by the time it comes in. At least, no excuse I can find.

    I keep thinking that I have a pin in input mode floating that needs a pull up or pull down resistor, but I've tried it both ways using 470 ohm resistors on each pin. It hasn't seemed to help.

    Does the BS2 use a crystal or resonator? This BS2 is many years old, and I'm wondering if the timing could have drifted enough to mess me up.

    Many bytes come in perfectly before I get garbage, like a dozen or so. The first command that requires a response works correctly, but the second doesn't.
  • stamptrolstamptrol Posts: 1,731
    edited 2009-01-16 16:14
    In your code, you are depending on the SERIN to halt and wait for serial activity. However, the way you're set up, it will grab the first byte coming along. You have no check that its even a byte you want.

    Main:
    ' SERIN HostRxPin, HostBaudMode, BadParity, TimeToWait, TimeoutOccured, [noparse][[/noparse]inbyte]
    SERIN HostRxPin, HostBaudMode, BadParity, [noparse][[/noparse]command]
    DEBUG "Rx Host Cmd $", HEX(command), 13
    GOSUB SetCommandParms
    'is it a NOOP?
    IF commandCode = 0 THEN EndCommand

    As has been suggested, use the WAIT modifier so you can put a start-of-data character for the Stamp to be watching for. As well, I'd grab all possible characters in one go and sort them out in the Stamp afterward. You can do that with the STR modifier.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
Sign In or Register to comment.