Using FullDuplexSerial....
This below is giving me trouble. Too 'newbie' to comprehend what's wrong.
Hitting F10 give me "Expected a unique parameter name". I've defined the pins, mode and baudrate up in CON.
I'm not sure if it should be in a separate or same cog as the main will run in.
I've seen some code where something is started, then shortly later it is stopped to free a cog. Wouldn't that mean the 'something' wouldn't be usable later?
Can anyone steer me to understanding getting a soft uart going?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
Hitting F10 give me "Expected a unique parameter name". I've defined the pins, mode and baudrate up in CON.
I'm not sure if it should be in a separate or same cog as the main will run in.
PRI uartD(rxpin, txpin, mode, baudrate) : okay '' Start this in another cog? rx := rxpin tx := txpin baud := clkfreq / baudrate okay := cognew(Control1, @stack) > 0
I've seen some code where something is started, then shortly later it is stopped to free a cog. Wouldn't that mean the 'something' wouldn't be usable later?
Can anyone steer me to understanding getting a soft uart going?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
Comments
In terms of what you're trying to do in your question, what do you want to actually do?
Also you need to pass the pointer to the communications buffers in cognew(Control1, @stack) but I am not sure what you are doing here with "stack".
When you invoke cognew you are requesting a new cog to run the code "Control1" which is loaded into that cog if successful. The cog you are requesting this from is obviously running the Spin interpreter. In the "okay :=" you are reading a flag but you lose out on finding out which cog was assigned, use the normal "+ 1" method and save that in a variable like "cog" so that you can stop it later on with cogstop.
P.S. I'm a newbie too especially when it comes to Spin so feel free to correct me if I'm wrong. I also see that Mike has answered your immediate question.
*Peter*
This design will be using a soft UART for comm to another board (uses a PIC running on 5v) and to another Prop (need more I/O, and some high speed stuff, than the first Prop). Figured I could use FullDuplexSerial in the main cog, and again in a another cog for the other Prop.
I've been studying the Monitor Demo trying to understand how to init the two soft UARTs and how to i/f with them; that is read from and write to the UARTs. I miss interrupts right now; can't get my head around 'no interrupts'. Can't figure out the 'hooks' that make it work.
Didn't figure getting this part working would be this much of a challenge. Wonder how many other surprises and challenges are in store.
Might there be a good example of handling FullDuplexSerial?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
If you want to use more than one soft UART, you will need to declare two copies of the FullDuplexSerial object. The Propeller Tool will make sure that there's only one copy of the program itself, but two copies of the data area.
Alternatively, you could have another cog communicate with the PIC and use the main cog to communicate with the other Propeller. In that case, you'd need to communicate back and forth between the two cogs much as if you had a co-processor for each cog (which is, in fact, what you have) just using common memory rather than a communications channel.
Now, it may take a while for me to study/understand what all is happening. I see now how both soft UARTs can be in the Main (Top object) program. Thought the second one would HAVE to be in a separate cog. Any advantage/disadvantage to having in same or in separate cogs? (Program space, flexibility, etc.?)
Presently the PIC UART is running at 38400 baud, and planned to also run the second Prop i/f at 38400. Hopefully that is no problem.
I'm constantly amazed what all people are having the Propeller do, and pleased to be working with it. Quite an exciting device.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
2) No problem running at 38400 Baud. The half duplex routines in SPIN work to 19200 Baud. The FullDuplexSerial routines should work to at least 384 kB.
3) The main reason for choosing to split a function into 2 cogs is simplicity. Interrupt routines and multithreading can get so convoluted sometimes and terrible to try to debug. Often, a very complex interaction can appear very straightforward when single threaded. On the Propeller, it's easy just to provide a separate processor to do the thread. Only where the threads have to interact do you have to do anything special and the semaphore stuff (LOCKxxx) is often all you need (if that).