Shop OBEX P1 Docs P2 Docs Learn Events
NEWBIE - help with FULLDUPLEXSERIAL.SPIN & USB2SER Adaptor — Parallax Forums

NEWBIE - help with FULLDUPLEXSERIAL.SPIN & USB2SER Adaptor

DavidMDavidM Posts: 626
edited 2007-02-09 08:41 in Propeller 1
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[noparse][[/noparse]16..23]~~ ''Sets all pins from 8 to 23 to outputs
outa[noparse][[/noparse]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[noparse][[/noparse]16]~~
$32 : outa[noparse][[/noparse]17]~~
$33 : outa[noparse][[/noparse]18]~~
$34 : outa[noparse][[/noparse]19]~~
$35 : outa[noparse][[/noparse]20]~~
$36 : outa[noparse][[/noparse]21]~~
$37 : outa[noparse][[/noparse]22]~~
$38 : outa[noparse][[/noparse]23]~~

waitcnt(20_000_000+CNT)
outa[noparse][[/noparse]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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-09 04:55
    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.John R. Posts: 1,376
    edited 2007-02-09 05:08
    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
  • DavidMDavidM Posts: 626
    edited 2007-02-09 05:16
    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 GreenMike Green Posts: 23,101
    edited 2007-02-09 05:25
    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 HebelMartin Hebel Posts: 1,239
    edited 2007-02-09 05:26
    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
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • DavidMDavidM Posts: 626
    edited 2007-02-09 05:30
    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! smile.gif

    regards

    Dave Metus
  • OzStampOzStamp Posts: 377
    edited 2007-02-09 08:41
    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
Sign In or Register to comment.