PDA

View Full Version : NEWBIE - help with FULLDUPLEXSERIAL.SPIN & USB2SER Adaptor



DavidM
02-09-2007, 11:34 AM
Hi,

I wish to communicate with the PROPELLOR vis SERIAL RS232.
I have the DEVELOPMENT BOARD and the USB2SER adaptor.

Q1) How do I wire up the USB2SER to the Prop.

I believe I need to wire up the USB 2SER as follows, but correct me if I am wrong.

VSS on USB2SER -->VSS on PROP ( next to pin 7 )
RX on USB2SER -->Pin 7 on the Prop
TX on USB2SER -->Pin 6 on the Prop

Q2) I firstly want to send some simple commands from a TERMINAL APPLICATION , using the number 1-8 and then when the prop receives them, the LED's 16 to 23 will flash for a second accordingly

eg

Send "1", LED 16 will flash for a second.
Send '2", LED 17 will flash for a second.
and so on..

I have written some code already, I have installed the FULLDUPLEXSERIAL.SPIN code and I am using that in my code. But I am confused on how to use the commands from that code, Are there any examples, or instructions for the fullduplexserial.spin code?

If I send the number "1" via the Serial terminal application to the PROP, then that is ASCII char(31), I believe, so if I have a case statement with each of the characters 31 to 38 then I should be able to flash an appropriate LED ( i.e 16-23)


here is my code I am using..

'' DAVES SERIAL TESTER


VAR
byte vData

CON
_CLKMODE =XTAL1 +PLL16X
_XINFREQ =5_000_000
rxpin =7
txpin =6
mode =0
baudrate =9600

PUB InitOutputLEDs

dira[16..23]~~ ''Sets all pins from 8 to 23 to outputs
outa[16..23]~ ''turn off all leds


OBJ
FullDuplexSerial : "FullDuplexSerial"

PUB StartSerialTester

FullDuplexSerial.Start(rxpin, txpin, mode, baudrate)

REPEAT

vData:= FullDuplexSerial.rx

CASE vData
$31 : outa[16]~~
$32 : outa[17]~~
$33 : outa[18]~~
$34 : outa[19]~~
$35 : outa[20]~~
$36 : outa[21]~~
$37 : outa[22]~~
$38 : outa[23]~~

waitcnt(20_000_000+CNT)
outa[16..23]~


The above code does not work!, What am I doing wrong? My RX light on the USB2SER is FLASHING, but nothing on the PROP Board is?

Thanks

Dave Metus

Mike Green
02-09-2007, 11:55 AM
The first PUB in the main program is the one that gets executed on a reset, so InitOutputLEDs executes, then everything stops. What you should do is to put InitOutputLEDs at the end so StartSerialTester comes first, but put a call to InitOutputLEDs before the REPEAT

John R.
02-09-2007, 12:08 PM
I believe you also have the Prop side of the pins reversed. The TX label on the USB2Ser is the RX side on the Prop, so I beleive you need this:

rxpin =6
txpin =7

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log (http://share.crustcrawler.com/JohnR/)

DavidM
02-09-2007, 12:16 PM
Thanks,

I have fixed up my PUB code, you are right it will just sit there, I have now revered my rx & tx pin assignment as well.

Am I using the case statement correctly? And am I getting the bytes from the receive command correctly?

regards

Dave M

Mike Green
02-09-2007, 12:25 PM
I know it may seem like overkill, but I really suggest that you get a little TV with a video in jack and plug it into the video out jack of the demo board, then add 'tv : "tv_text"' to your program after the OBJ header. Add 'tv.start(12)' as the first statement of your main routine. You can then use statements like 'tv.str(string("this is a line",13))' for labels or 'tv.dec(555)' for numbers or even 'tv.hex($A535,4)' to display 4 hex digits. That way, you can see what your program is actually doing. It helps immensely for debugging or even just understanding what's happening.

Martin Hebel
02-09-2007, 12:26 PM
It helps to find errors by sending data back the terminal.

After you receive data, send it back to the computer:
FullDuplexSerial.tx(vDat)

When you post code, use the CODE button on the editor to start and end a block of code, it helps to see your indentations.

-Maritn

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters (http://www.selmaware.com/)
Southern Illinois University Carbondale, Electronic Systems Technologies (http://www.siu.edu/~isat/est)

DavidM
02-09-2007, 12:30 PM
Thanks Mike,

I might try that TV stuff you mentioned, I am a programmer already ( 4D database for 3 years) so I now how to write code, without a debugger, its difficult, but your suggestion is a great idea.

By the way I DID GET MY CODE to WORK! yippee!

I had to pay close attention to the INDENTATION from the REPEAT statement, and the very fussy ( and unusual to me) nature of the syntax that spin uses.

Thanks to the other as well.


I feel I have accomplished something! http://forums.parallax.com/images/smilies/smile.gif

regards

Dave Metus

OzStamp
02-09-2007, 03:41 PM
Hi Dave M and other

Dave as promised some stuff that we spoke about today.
The ADC0831 spin file was an example we did for a customer that was using a Basic Stamp1
sampling an 8 bit a/d converter chip... hacked some code that looked similar .. not the most
elegant way but it shows you the principle of clocking .. looking at data .. addding data as you loop
and finally outputting the data to PINS and doing a compare ....
This was done ages ago...
More stuff attached as well .. though tI share it with all ..

Ronald Nollet···· Australia