Propeller to BS2E
Newzed
Posts: 2,503
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
Sid
Comments
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
Sid
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
Sid
-Martin
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
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
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
Baud 16468 is inverted. Try 84 instead.
-Phil
·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
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
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
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
************************************************************************
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
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
·
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
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Need a little board made on SuperMill?· No charge for you.
Sid
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
Thanks
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
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
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.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Southern Illinois University Carbondale - Electronic Systems Technologies
Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control
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
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
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
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
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Southern Illinois University Carbondale - Electronic Systems Technologies
Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control