Propeller commands similar to Basic Stamp (BS2) functions
I am wondering if anyone knows how to execute commands on Propeller similar to that of Basic Stamp commands. On the OBEX, I downloaded a "BS2_Functions" file to use certain commands; most of them work, but I realized that the serin/serout commands were faulty in some of its uses. In other words, some pieces of the code were not full-proof; I had to touch up on some of them, and some serin/serout PUB routines could not be understood. I am wondering if anyone has some source code on SPIN to access and mimic BS2 commands. Another solution would be if someone out there knew a solution to the serin/serout commands on the "BS2_Functions" file so that I could possibly use them.
I want to send more than 8 bits through a serout (either through decimal, binary, or hexadecimal). I also want to receive more than 8 bits through a serin. If possible, I am wondering if there is a flag to set in order to execute a serin (i.e. not a character, but some sort of flag). Thank you very much to anyone out there who is considering a solution.
-square
I want to send more than 8 bits through a serout (either through decimal, binary, or hexadecimal). I also want to receive more than 8 bits through a serin. If possible, I am wondering if there is a flag to set in order to execute a serin (i.e. not a character, but some sort of flag). Thank you very much to anyone out there who is considering a solution.
-square
Comments
2) The SERIN_CHAR and SEROUT_CHAR routines in the BS2_Functions object are designed to receive and transmit any number of bits. The I/O pin number, Baud, Inverted/Non-inverted mode, and number of bits are all specified as parameters. Note that, if you use anything other than 8 bits, you won't be able to communicate with most PCs and most other devices. If you need to transmit a value with more than 8 bits, you can break it up into two 8 bit values and reassemble it on the receive end.
3) What do you mean by a "flag"?
Anyway, I ended up building heater and cluso's CP/M emulation so I could program in Basic on the prop. eg
A$="Hello World"
for i=1 to len(a$)
out(&H78),asc(mid$(a$,i,1))
next i
which does a serout of 'Hello World" to a serial port.
And in doing so I had to learn Spin to write the emulation. And finally at the end of that, I found I didn't need the Basic emulation so much as I had learned Spin!
So - although it is a steep learning curve, rather than trying to shoehorn BS2 into the Prop, I think it is worth trying to learn some Spin. It isn't that different to BS2, and my personal view is that Spin is a sort of hybrid of Basic and C and Pascal, so by learning Spin you also learn C and Pascal and that is useful too.
Re flags, do you mean a flag to detect if a byte has arrived on a serial port?
This is a *Very Big Problem* for the picaxe, as you can't test for a byte arriving (or at least not unless you get some of the very latest chips which cost more than the propeller). All you can do is execute a serin and the whole chip hangs till a byte arrives.
On the prop, you can read bytes into a buffer in the background then check them when you are ready. This is where the parallel processing really shines. So on the CP/M emulation you can do an INP(&H7D) which returns 32 or 33 depending on whether there is a byte (or more than 1) available and if yes, then you read it in with INP(&H78).
And then there is Bean's Basic Compiler which ought to provide a crossover for BS2 programmers.
And the Catalina C compiler for those coming from Arduino.
The best bit about this forum is there are many people willing to help out with the most simple questions - especially when starting out with Spin. All you need to do is desribe the problem a bit more, and almost invariably, within a few hours, someone has kindly posted some spin code.
Most times it is then a matter of "see one, do one, teach one".
So - do you want to send out "Hello World" from a serial port?
Or, do you want to read "Hello World" from a serial port? And if so, do you know in advance when it will arrive, are you polling waiting for it to arrive, are the packets less or more than n characters (ie bigger than the buffer), and do you know in advance how many bytes in "Hello World"? The answers to those questions affects what sort of polling you do, whether you have timeouts etc.
Can you describe the whole project a bit more, eg hardware, and I'm sure we can all get it working.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 1/21/2010 10:55:19 AM GMT
However, for the serin, I notice that the "BS2_Function" does not have "serin_wait" for binary numbers, and I'm not quite sure what two of the arguments mean. The format goes x := serin_wait([noparse][[/noparse]Pin],Value,@mystring,char,BAUD,mode,bits). What does "@mystring" signify? I also undersand that "char" waits for a character, but where does the character have to reside in order to check it/be flagged? Thank you all for your time.
-square
SERIN_WAIT is like the WAIT() clause in the BS2 SERIN statement. @mystring is the address of the string to wait for. Spin does have a shortcut to produce an address from a literal string and you can substitute this in place of @mystring. It would be STRING("Hello World")
SERIN_CHAR causes the cog to wait for any character to be received, then it returns the character. There's no "flag" involved. It's like writing
SERIN <pin>,<Baud>,[noparse][[/noparse]byteChar]
where "byteChar" is declared as a byte variable.
-square
I made a mistake. Sorry. SERIN_WAIT isn't like the WAIT() clause in the SERIN statement. It does something different.
Best thing is to read the source code for BS2_Functions.spin and look at the comments associated with each routine. Many of these comments include examples of the use of the particular routine including an explanation. Also look at BS2_Func_Test.spin which shows the use of many of the other routines in BS2_Functions.spin.
-square
-square
repeat
BS2.serout_str(7,string("Hello World",13),9600,1,8)
BS2.serin_str(5,string("Hello World"),9600,1,8)
waitcnt(900_000_000 + cnt)
The "serout" statement works perfectly, but all of the "serin" statements do not work (i.e. debug_, serin_char, etc.). When the SPIN executes the "serin_str" command, it idles. I am wondering what is wrong with my code. Thank you for your time.
-square
humanoido