Shop OBEX P1 Docs P2 Docs Learn Events
Propeller to BS2E — Parallax Forums

Propeller to BS2E

NewzedNewzed Posts: 2,503
edited 2006-08-22 23:14 in Propeller 1
Mike, could you please show me how to make my Propeller communicate with my BS2E via "serout".· I have studied the BS2_Function object but I'm not sure I understand it.· Thanks.

Sid
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-09 14:14
    1) What is confusing to you about the BS2_Function object?

    2) If you're not using the other BS2 compatibility methods, it may be more useful to use the FullDuplexSerial object.

    3) What do you want to do with the BS2E connection? Are you pretty sure/comfortable with what you want on the BS2e end?

    Mike
  • NewzedNewzed Posts: 2,503
    edited 2006-08-09 14:19
    Mike, I want to send one byte to the BS2E - A, B, C, etc.· The BS2E will receive this byte, decode it and perorm a task.· I do not foresee a requirement for the BS2E to reply to the Prop.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-09 14:26
    The BS2_Functions SEROUT is pretty straight forward, but you have to ensure you use the BS2.Start method otherwise the clock speeds won't be set.

    I'd give you better code example, but it's on my other computer...

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-09 14:30
    Martin, if you have a code that will let the Prop talk to my BS2E, I'll be happy to wait for it until you can get to your other computer.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-09 14:41
    OK, installed what I needed here. This should work for you, or as mentioned, use the FullDuplex routines.

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
                       
    VAR    ' Global Variables and Cog Stack Space
      Long stack0[noparse][[/noparse]50]
       
    
    OBJ
    
      BS2 : "BS2_Functions"                    ' Create BS2 Object
    
    
    PUB Start
        BS2.start (31,30)                       ' Initialize BS2 Object, Rx and Tx pins for DEBUG
        CogNew(SendData, @Stack0)            ' Cog to measure RC Time
     
    
    PUB SendData
      Repeat      ' Sends data on Pin 5, once a second for each character
        BS2.Serout_Char(5,"A",9600,BS2#NInv,8)
        BS2.PAUSE(1000)
        BS2.Serout_Char(5,"B",9600,BS2#NInv,8)
        BS2.PAUSE(1000)
        BS2.Serout_Char(5,"C",9600,BS2#NInv,8)
        BS2.PAUSE(1000)
        BS2.Serout_Char(5,"D",9600,BS2#NInv,8)
        BS2.PAUSE(1000) 
    
    



    -Martin
  • NewzedNewzed Posts: 2,503
    edited 2006-08-09 19:47
    Martin, I downloaded your code and studied it.· My situation is that I want to be able to send a command to the Stamp at various points in my program and the command might be any letter.· So I sort of chewed up your program.· You have to understand that I really don't know what I'm doing
    with SPIN yet -· I write something and if that doesn't do what I want I write something else, and
    so on until I get what I want.· I finally got the Prop to turn an LED on and off in the Stamp, and if I can control an LED then I can control anything.· Here is the program I would up with:

    *************************************************************************

    CON
    · _clkmode = xtal1 + pll16x
    · _xinfreq = 5_000_000

    · kbpin = 26· 'added

    ··················
    VAR··· ' Global Variables and Cog Stack Space
    · Long stack0[noparse][[/noparse]50]
    · word cmd

    OBJ

    · BS2 : "BS2_Functions"··················· ' Create BS2 Object
    · kb: "keyboard"····························· 'added
    · text:·· "vga_textA"······················· 'added

    PUB Start
    ··· BS2.start (31,30)······················ ' Initialize BS2 Object, Rx and Tx pins for DEBUG
    ··· 'CogNew(SendData, @Stack0)······'··I deleted this line
    ··· text.start(16)··························· ' start VGA
    ··· verifykeyboard·························· 'start keyboard

    ··· text.str(string(12,5,"Running Prop_Stamp· 8/9/06", 13,13))
    ··· command
    ···
    PUB command
    ··· text.str(string(12,6,"Enter command:· "))
    ··· cmd := kb.getkey
    ··· text.str(string("You entered:· "))
    ··· text.out(cmd)
    ··· text.out(13)
    ··· text.str(string("Press G to continue-C to cancel",13))
    ··· if kb.getkey == "g"
    ····· senddata
    ··· else
    ····· start
    PUB SendData
    ··· BS2.Serout_Char(8,cmd,9600,BS2#NInv,8)
    ··· text.str(string(12,1,"Sent "))
    ··· text.out(cmd)
    ··· text.out(13)
    ··· BS2.PAUSE(1000)
    ··· start

    ·PRI verifyKeyboard·············· 'start the keyboard
    · kb.start(kbPin, kbPin+1)
    · waitcnt(clkfreq/2 + cnt)
    **************************************************************************· My idea is that I can call "PUB command" from anywhere in my program to send a command to the Stamp.· I was going to make it a PRI method but I left well enough alone.· When I enter an "a" from the Prop keyboard, the LED turns on.· When I enter a "b" the LED goes off.· So it is working so far.

    I had another little problem - if you send an "a" from the Prop the Stamp does not translate that to "A" - instead the Stamp debugs an "O".· I 'dec debugged' five characters received from the Prop and this is what I got:

    ···Prop·· Stamp··· ASCII
    ····· a =··· 79 =···· O
    ····· b =··· 39 =···· '
    ····· c =··· 78 =··· ·N
    ····· d =··· 19 =···· No character
    ····· e =··· 77 =···· M

    I could detect no mathematical relationship between what the Prop sent and what the Stamp got, so I simply 'dec debugged' what the Stamp received for various byte commands and wrote "if com = dec whatever then do so and so".· Seems to work so that is all I can ask for.· There are probably much better ways to do it, but remember I'm just a Second Class Junior Apprentice Propeller guru.

    Thanks for your help, Martin.· Now I can press on.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-09 20:04
    Sid, the character should be transferred over pretty cleanly. Make sure you are using the 9600 non-inverted value on the BS2E.
    Programming wise, besides the option to have unique programs running in cogs, programming is programming. Think through the flow and write a program to meet it. I don't know what help you may need from your post, so if there is something in particular, please ask.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-09 21:12
    Martin, I added the little program to my SuperMill program and added a menu option:

    X - Send command to Stamp

    If I press "X", the screen clears and I get a little sub-menu telling me what command to enter to
    accomplish a given task.· I added a couple of lines to convert lower case to upper case and
    the whole program is working beautifully.· I have effectively added 15 pins to the Prop's 32 pins, which gives me tremendous flexibility to run peripheral devices.· I don't understand why an A from the Prop doesn't result in an A on the Stamp, but I do have a workaround.· The Stamp is running at baud CON 16468, so I don't know what the problem is.· Thanks for all our help, Martin.· If you have any ideas about the character difference it would be nice to get them the same.

    Sid
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-08-09 21:40
    Sid,

    Baud 16468 is inverted. Try 84 instead.

    -Phil
  • NewzedNewzed Posts: 2,503
    edited 2006-08-09 21:50
    That did it, Phil.· Thanks a million.· The BS2_function says:

    ·BS2.Serout_Char(8,cmd,9600,BS2#NInv,8)

    so I figured the Stamp would use 16468.· Maybe the BS2 line is inverting the 9600 inverted from the
    Prop so maybe the end result is 84.· Don't know, but now it works.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-09 22:51
    Sid,
    On the Prop you are sending non-inverted, and on the BS2 you are receiving non-inverted. All is right with the world [noparse]:)[/noparse]

    Sounds like a fun project, glad the BS2_Functions library is of use to you.

    On a side note, maybe someday my name will be listed on the Propeller Libraries page again for it [noparse]:)[/noparse]

    -Martin
  • NewzedNewzed Posts: 2,503
    edited 2006-08-10 18:37
    Martin, I decided I would make the Prop-Stamo communication two-way, so I added PUB recData
    right after the PUB SendData:
    **************************************************************************

    PUB SendData
    · 'Repeat····· ' Sends data on Pin 5, once a second for each character
    ··· BS2.Serout_Char(8,cmd,9600,BS2#NInv,8)
    ··· text.str(string(12,1,"Sent "))
    ··· text.out(cmd)
    ··· text.out(13)
    ··· BS2.PAUSE(1000)
    ··· recData

    PUB recData
    ··· BS2.Serin_Char(8,9600,BS2#NInv,8)
    ··· text.str(string(12,4,"Received:· "))
    ··· text.out(ByteVal)
    ··· text.out(13)
    ··· BS2.PAUSE(1000)
    ··· start1
    *************************************************************************

    I'm using the same Prop pin for serout and serin.· In studying BS2_functions, I gathered that:

    PUB SERIN_CHAR(pin, Baud, Mode, Bits) : ByteVal | x, BR

    means that· the 8 incoming bits are stored in Byteval.· Does PUB recData look like it will work?

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-10 19:00
    Sid,
    The doc for that one could be a little better. You need to store it in a local variable:

    PUB recData | ByteVal
    ByteVal := BS2.Serin_Char(8,9600,BS2#NInv,8)
    text.str(string(12,4,"Received: "))
    text.out(ByteVal)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-10 21:08
    OK, Martin, I did that.· When a send "A" to turn the LED on, it turns on.· As soon as I execute "SendData" I call "recData".· However, everytime I get a different letter back, sometimes a letter, some times a hieroglyphic.· Here is the Stamp snippet:

    ************************************************************************
    IF com = "A" THEN
    HIGH 15
    DEBUG "LED On", cr
    'GOTO start
    PAUSE 1000
    SEROUT si, baud, [noparse][[/noparse]"A"]
    ENDIF
    ***************************************************************************

    Here is the Prop snippet:

    **************************************************************************
    ··· text.str(string(12,4,"You entered:· "))
    ··· text.out(cmd)
    ··· text.out(13)
    ··· senddata
    ··· recdata
    ··· waitcnt(clkfreq + cnt)
    ··· start1

    ·PUB SendData
    ··· BS2.Serout_Char(8,cmd,9600,BS2#NInv,8)
    ··· text.out(13)
    ··· waitcnt(clkfreq/4 + cnt)

    ·PUB recData | Byteval
    ··· text.str(string(12,4,"Received:· "))··
    ··· BS2.Serin_Char(8,9600,BS2#NInv,8)
    ··· text.out(ByteVal)
    ··· text.out(13)
    *************************************************************************

    What do I have wrong?·

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-08-10 21:44
    Martin, I changed
    text.out(Byteval)
    to
    text.dec(Byteval)

    and I get a huge 9 or 10 digit number, sometimes positive, sometimes negative.· Does that tell you anything?

    Sid

    ·
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-10 21:50
    Sid,
    I'd read returning data immediately following sending data so you don't miss the return. Also, you still aren't assigning the value returned by the function:

    PUB recData | Byteval
    ByteVal := BS2.Serin_Char(8,9600,BS2#NInv,8)
    text.str(string(12,4,"Received: "))
    text.out(ByteVal)
    text.out(13)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-10 22:54
    Martin, I missed the Byteval assignment when I read your previous post.· I'll put that in and see what happens.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • NewzedNewzed Posts: 2,503
    edited 2006-08-10 22:59
    Martin, everything is working beautifully now.· Thanks a million - you are a very patient person.

    Need a little board made on SuperMill?· No charge for you.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-11 00:33
    Who am I to pass up something for free?? lol. Plus what you've done is pretty impressive, I've seen your images.
    I'll send you a private.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-19 23:32
    Martin, I can foresee a need for flow control once my program gets a little more complex.· How would I set this up between the Stamp and the Prop.· I know how to do it with the Stamp but I'm not sure about the Propeller end.

    Thanks

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-19 23:47
    The Propeller end does have a 16 byte buffer in the FullDuplexSerial object. There's no reason why this can't be made bigger. The routines are written for a buffer size that's a multiple of two (using bit masks for wraparound of buffer pointers) and that could be 32, 64, etc. The transmit and receive buffers could even be different sizes. With a Stamp at the other end, you're not likely to need flow control at the Propeller end.
  • NewzedNewzed Posts: 2,503
    edited 2006-08-20 21:57
    Martin, I have my new Propeller board up and running and communicating with my Stamp on a byte basis.· Now I would like for the Stamp to send a string to the Propeller, and then have the Propeller display the string on the VGA.· For a starter, I wrote the following method in my program:

    PUB recstr | ptr
    ··· dira[noparse][[/noparse]1]~
    ··· bytefill(@DataIn,1,49)
    ·· ·repeat while DataIn[noparse][[/noparse]ptr] <> 13
    ······ ptr++
    ······ dataIn[noparse][[/noparse]ptr] :=BS2.SERIN_CHAR(1,9600,BS2#NInv,8)··· ' Store character in string
    ··· dataIn[noparse][[/noparse]ptr]:=0········································ ' set last character to null
    ··· byteMove(stringptr,@DataIn,50)

    That's as far as I can get.· I think the incoming string is stored in DataIn but I'm not sure.· If so, how do I display DataIn on my VGA.

    Thanks for the help when you have time.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-21 00:35
    Sid, sitting in an airport now, but his is form the docs on it (and these SHOULD be correct). It's not one that is assigned, you need to pass a pointer to it.

    As to your Q on flow control, on the Prop side you can use WAITPEQ to wait for the basic stamp to assert a pin prior to sending data using the BS2 function.

    PUB SERIN_STR (Pin,stringptr,Baud,Mode,Bits) | ptr
    {{
      Accepts a character string on defnined Pin at Baud for bits/char, up through a CR (13)
      Maximum is 49 character, such as "abc, 123, you and me!" 
      Will cause cog-lockup while waiting without a cog-watchdog (see distributed example)
      NOTE: There is NO buffer overflow protection.
      
    VAR
        Byte myString[noparse][[/noparse]50]  
    
        Repeat
            BS2.Serin_Str(5,@myString,9600,1,8)   ' Accept string passing pointer for variable
            BS2.Debug_Str(@myString)              ' display string at pointer
            BS2.Debug_Char(13)                    ' CR
            BS2.Debug_Char(myString)           ' show 6th character
    }}
    



    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-21 12:31
    Martin, you areconfusing me.· The section of code you posted is commented out in the BS2.function.· If I write in my program:

    PUB recstr
    ··· your code

    Will that let the prop receive a string from the Stamp?· I don't see any reference to "text.out(****)" to send something to my VGA.· What about the active code in BS2.function:

    PUB SERIN_STR (Pin,stringptr,Baud,Mode,Bits) | ptr

    · dira[noparse][[/noparse]pin]~············································ ' Set pin to input
    ··· bytefill(@dataIn,1,49)································ ' Fill string memory with 0's (null)
    ··· repeat while DataIn[noparse][[/noparse]ptr] <> 13························ ' accept character and until CR
    ······ ptr++
    ······ dataIn[noparse][[/noparse]ptr] := SERIN_CHAR(Pin, Baud, Mode, Bits)··· ' Store character in string
    ······ text.out(dataIn[noparse][[/noparse]ptr])······· 'Would this display each char on my VGA?
    ··· dataIn[noparse][[/noparse]ptr]:=0········································ ' set last character to null
    ··· byteMove(stringptr,@datain,50)························ ' move into string pointer position

    Doesn't that have to be in my program somewhere?

    Do you have time to write a method for me that will receive a string and display it on my VGA?
    My serin pin is Pin 1.· Sorry to be so much trouble.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-21 12:52
    SId, the documentation shows how to call and use the functions. You're not going to put the actual function code in your program.

    VAR
    Byte myString[noparse][[/noparse]50]

    Pub GetData
    Repeat
    BS2.Serin_Str(1,@myString,9600,1,8) ' Accept string passing pointer for variable
    txt.out(@myString) ' display string

    I haven't played with the VGA text out yet (or much else for the past 5 months), so the above is an educated guess?
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • NewzedNewzed Posts: 2,503
    edited 2006-08-21 14:06
    Martin, I received your post via e-mail, but it doesn't show up in the forum.

    I added mystring[noparse][[/noparse]50] to my VAR block.

    I wrote in my Prop program:

    PUB getdata
    · Repeat
    ······· BS2.Serin_Str(1,@myString,9600,1,8)·· ' Accept string passing pointer for variable
    ······· text.out(@myString)····························· ' display string
    ··
    I wrote in my Stamp program:

    IF com = "C" THEN
    HIGH 1
    PAUSE 10
    SEROUT so, baud, [noparse][[/noparse]"OK",13]
    GOTO start
    ENDIF

    If I send "C" from the Prop, the Stamp LED turns on, the Prop displays a single hieroglyphic and then locks up like it was waiting for something else.· Have I overlooked something?

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-08-21 14:36
    Martin, I found a workaround so relax.· I had a recdata method that I was using to receive a single byte.· I modified recdata:

    PUB recData | Byteval
    · repeat while byteval<>13··
    ··· Byteval := BS2.Serin_Char(1,9600,BS2#NInv,8)
    ··· text.out(Byteval)

    I am now receiving strings from the Stamp so I guess everything is OK.· Should have tried that before I asked you for help - wasn't following my own rules.

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-08-21 19:45
    Martin, this whole thing is working great.· I have it now so that when I send
    the proper command to the Stamp, it sends the Prop its DS1302 time and
    my VGA displays:

    Time is:· 15:36:42

    I redid the "recdata" method so that if the command is "G" - for G(et time) -
    the method is terminated after it has received six digits.· I had to write three
    "senddata" methods.· senddata is for sending commands to the Stamp,
    senddata1 is for requesting the time from the Stamp and senddata2 is sort
    of a dummy that initializes communication between the Prop and the Stamp.

    Your BS2.functions is a great tool - now that I am beginning to understand
    how it works I will be using it a lot.· Thank you for that, Martin.· Having the
    Stamp is like adding 16 pins to the Prop.

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-08-21 20:16
    Forgot to mention Martin - had to change

    repeat while byteval<>13

    to say

    repeat while byteval<>10

    If the hrs, mins or secs ever equalled 13 recdata would stop.· One
    other thing - I connected my Com2Prop board to a USB port via
    my USB2Ser adapter.· Now I can monitor or reload either the
    Stamp or the Prop without having to switch my DB9 connector.

    Sid
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-08-21 20:43
    Sounds very cool Sid, glad it's helping! You're learning quickly [noparse]:)[/noparse]

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
Sign In or Register to comment.