BS2E to Propeller Backpack Half Duplex I/O Example (was weirdness)
Martin_H
Posts: 4,051
I have a project where I need to use the propeller backpack's bottom three pin header for half duplex bi-directional communication with a BS2E. So I figured I would write a simple app that sent a string between the microcontrollers to learn how to do it.
So I send a string from the BS2E to the propeller backpack and the prop sends the string to the serial terminal. It mostly works except the first 2 or 3 bytes sent are garbled on the Parallax Serial Terminal.
Here's the Spin code prop backpack side:
Here's the PBasic code Stamp side:
Anyone see any gotchas with what I'm doing?
As an FYI, the propeller backpack is one slick piece of engineering.
So I send a string from the BS2E to the propeller backpack and the prop sends the string to the serial terminal. It mostly works except the first 2 or 3 bytes sent are garbled on the Parallax Serial Terminal.
Here's the Spin code prop backpack side:
CON _clkmode = xtal1 + pll8x _xinfreq = 10_000_000 OBJ pst : "Parallax Serial Terminal" io : "basic_sio" PUB start | i dira[16..17]~~ pst.Start(115200) pst.str(STRING("I/O TestStart", 13)) io.start repeat pst.Char(io.in)
Here's the PBasic code Stamp side:
io PIN 6 ' Serial I/O pin for Propeller Backpack. #SELECT $STAMP #CASE BS2, BS2E, BS2PE baud CON 84 + 32768 #CASE BS2SX, BS2P baud CON 240 + 32768 #CASE BS2PX baud CON 396 + 32768 #ENDSELECT DEBUG "Program starts here", CR LOW io 'Reset the Propeller Backpack PAUSE 500 INPUT io PAUSE 2000 'Wait for it to come out of reset. DEBUG "Propeller out of reset", CR 'Start sending data for the demo. SEROUT io, baud, ["This is a demo of the Propeller Backpack"] DEBUG "Data sent", CR
Anyone see any gotchas with what I'm doing?
As an FYI, the propeller backpack is one slick piece of engineering.
Comments
1) Stamp's aren't real good for high baud rates, try a more sedate 19,200
2) Is there a pull-up resistor on the transmit line from the Stamp? Otherwise it will float and generate garbage on the Prop's side
Put your io.start ahead of everything else. You want it ready to receive characters right away.
(And thanks for the "slick" comment! )
-Phil
1. He's using 9600 baud from the Stamp.
2. The Backpack provides the pull-up.
-Phil
For the final step I modified the Spin code to echo the character back (using io.out(theChar)), and added a serin after the serout in the pbasic code. That didn't work and it looked like the Basic stamp is hanging on the serin. I'm guessing that by the time the Basic Stamp was ready, the Prop already sent the character. So I added a waitcnt in the Spin code, but to no avail.
Current Spin:
Current PBasic:
Now I've done serout and serin full duplex on separate pins in pbasic, but never half duplex on a single pin. Are there any examples around? I imagine changing the pin from an output to an input and flow control are the challenge here.
-Phil
I could use the propeller backpack's tx and rx lines for full duplex communication with the Basic Stamp, but I'd like to be able to keep the line scan camera updating the PC based line scan camera monitor program. Plus the propeller backpack's manual mentioned the use of half duplex communication on the single pin and I've never seen it done.
Thanks for the help as this is new territory to me.
In your BS2 program you have the following line:
This waits for a string of ones and zeroes, which is not what the Backpack is sending. Eliminate the "BIN", and the program will work as expected.
-Phil
Serin is a really powerful command, and I am at survival mode with it. So I generally look for cut and paste reuse with it. Is there some trick to debugging it or is it school of hard knocks to know what to look for?
For anyone else following this thread who wants to do half duplex single pin communication. Here's the updated code:
Final Spin:
Final PBasic:
You'll note in the Spin code a small waitcnt is required. I removed that line and the message was garbled, so I kept reducing the waitcnt until it was small enough that I lost interest in optimizing it further. In the real app it will likely be unneeded because processing the command will take the required time.
I'm fairly sure I would find this sort of thing would be impossible to do on another Microcontroller.