Serial input loosing data
rdingham
Posts: 5
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.
I'm stumped.
Comments
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
·
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.
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.
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
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.
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
·