Serin\Serout to BS2
SteveD
Posts: 64
I am having trouble trying to figure out how to send a word sized variable to a BS2 from an SX28 using SX/B as a compiler.· The BS2 would be a master, an SX28 would be a slave.· I would like to·display this variable on the BS2's debug screen.· Thank you for any help you can give me.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
· TX_BYTE tempLo
· TX_BYTE tempHi
Where tempLo and tempHi are are the two bytes that build your 16-bit value.
[noparse][[/noparse]Edit] I don't have any spare time, so I can't write and test a custom program for you.· That said, I was working with serial stuff the other day and I've stripped everything out of my program except the core of what you need.· Start with this.· Make sure your SERIN on the BASIC Stamp is set to receive low-byte, then high-byte.· On the BASIC Stamp end you should be able to DEBUG in HEX4 mode and see $1234 coming from the SX every second.
And, don't use "magic numbers" in your PBASIC programs for the baudmode values -- this is the quickest way to an error.· I've posted my PBASIC program at least a dozen times ... I guess one more won't hurt.· I has all the baud rate and mode values built-in and saves a lot of errors if one will just use it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 11/1/2005 6:30:53 PM GMT
Would someone point out to me what I am doing wrong here?
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
temp con 200
' =========================================================================
PROGRAM Start
' =========================================================================
Start:
PLP_A = %0001
PLP_B = %00000000
PLP_C = %00000000
Main:
pause 3000
SEROUT RA.0, T2400, temp
GOTO Main
****************************************************************************
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
DataIO PIN 7
'
[noparse][[/noparse] Constants ]
T2400 CON 396
'
[noparse][[/noparse] Variables ]
Reply VAR Byte 'Holds information sent from slave(s)
'
[noparse][[/noparse] Initialization ]
Setup:
DEBUG CLS
'
[noparse][[/noparse] Program Code ]
MAIN:
SERIN DataIO, T2400, [noparse][[/noparse]Reply]
DEBUG DEC REPLY: PAUSE 1000
DEBUG CLS
GOTO MAIN
PLP_A = %1110
... to enable the pullup or RA.0 -- yes, this is the opposite of PBASIC and something you have to keep in mind when going back an forth between the two languages.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Main:
· SERIN DataIO, T2400, [noparse][[/noparse]reply]
· DEBUG DEC reply, CR
· GOTO Main
That way you can see the value come in and be received properly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
DEVICE··· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ······4_000_000
TestVal·· CON·· 200
PROGRAM Start
Start:
· PLP_A = %1110
Main:
· PAUSE 1000
· SEROUT RA.0, T2400, TestVal
· GOTO Main
Here's the BS2 compliment to it:
' {$STAMP BS2}
' {$PBASIC 2.5}
DataIO· PIN···· 15
·
T2400·· CON···· 396
·
reply·· VAR···· Byte
·
Setup:
· DEBUG CLS
·
Main:
· SERIN DataIO, T2400, [noparse][[/noparse]reply]
· DEBUG DEC reply, CR
· GOTO Main
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Do you have a common ground connection·between the BS2 and the SX ?
What are you using to clock the SX chip ? Is it 4Mhz ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
Those that would give up freedom for security will have neither.
Post Edited (Bean (Hitt Consulting)) : 11/4/2005 6:07:55 PM GMT
I'm setup on a PDB and am using one wire: between RA.0 on the SX and pin 15 on my BASIC Stamp. I have no idea what's going on at your end, but I can assure you that the code I posted does in fact work. Maybe you got a bad pin on either side. You could try a different pin -- just remember that you need to use 0 in the PLP register to pull-up the SX I/O pin.
DEBUG output has nothing to do with the baud rate between the SX and the BASIC Stamp -- and in all BS2 modules except the BS2px, DEBUG is at 9600 baud.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Yes to the common ground. 4MHZ internal clock. Thanks for answering the "Debug at 9600" I never paid attention to it before. I have tried external pull-up and pull-down resitors with the same response. The last time time I ran the program the debug RX indicator reacted only when I moved my hand close the PDB and I could tell that there was definitely not a 1 second pause between receiving. I know that the problem is not with the Stamp, I have a BOE, I hooked it to the PDB SX, same thing.
Jon
I too switched pins on the stamp to reflect your code and even tried different pins on the SX and same response. I feel much better knowing that I have at least a primitive understanding of sending the code between the two. Thanks for your time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I know I wasted some of your time but I appreciate you giving me a better understanding of serial communication and showing me how to use the resonator.
It works now and I even have the Stamp displaying a word sized variable from information sent from the SX!
Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax