Full Duplex Serial: Simultaneous Read and Write
flo
Posts: 38
I'm having problems transmitting and receiving simultaneously on my propeller using the FullDuplexSerial.spin object.
My propeller has a few buttons wired to the I/O pins and is listening for command strings sent from the computer over the USB cable. I want the propeller to alert the computer when a button was pressed.
Right now I have 2 cogs running where Comm is just listening for strings and Comm2 is sending strings out:
But this doesn't work. I'm not receiving anything on the computer side. I know my software on the computer works because I can simply echo back what's received and I can read it. It seems like the scanButtons cog is crashing.
Is it because I have 2 cogs trying to access the same I/O pins?
My propeller has a few buttons wired to the I/O pins and is listening for command strings sent from the computer over the USB cable. I want the propeller to alert the computer when a button was pressed.
Right now I have 2 cogs running where Comm is just listening for strings and Comm2 is sending strings out:
Comm.start(31,30,0,9600) Comm2.start(31,30,0,9600) cogBtnScan := cognew(scanButtons,BtnScanStack) repeat Comm.RxStr(@x) '....parses string and does stuff with it PRI scanButtons dira := 1 repeat '...read button states; lets say button "a" was pressed, then: Comm2.str(string("a",13)) waitcnt(cnt+8_000_000)
But this doesn't work. I'm not receiving anything on the computer side. I know my software on the computer works because I can simply echo back what's received and I can read it. It seems like the scanButtons cog is crashing.
Is it because I have 2 cogs trying to access the same I/O pins?
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
Are objects only accessible to the cog that created them?
if you ATTACH your COMPLETE code to a posting
like shown in the picture, the community can give much better advise without guessing through the fog what MIGHT be
around your quoted code.
As a quick hint
if two different cog call FullDuplexSerial at overlapping times the buffers were mixed up.
What do you guess comes out if two people talk at the same time?
best regards
Stefan
I looked through FullDuplexSerial and it has 2 buffers: tx and rx. I don't completely understand whats going on, but it doesn't look like rx_buffer is using tx_buffer and Vice Versa.
Thanks for the help guys.
So if I understand localroger, you would do something like this in a single cog:
scanButtons
if buttons have changed -> send serial string out
receive Serial Command in but with a timeout
repeat
I attached the zip archive to my previous post. Do you guys see it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
first of all compliment about your formatting of the spin-file well done
I downloaded your code and have several hints about bugs
maybe it is working with 6 longs but
the absolute minimum for stacksize is 9 longs. Better use 50 longs to have some extra space if parameters or function calls are added
So the crash of the program is caused by the call of COBINED with the too small stack of 6 longs.
the at-operator "@" is missing
You don't have to re-invent the wheel again. The RxStr-method is already able to receive a string (=bytesequence of 1-15 bytes terminated by the delimiter character
As ExtFDS is running in its own cog. Just send the string up to 15 characters (plus delimitercharacter) are stored in the receivebuffer of ExtFDS and as long as you
don't send any more characters these characters stay ready to read out in the buffer. Your program can do other things for hours and days. If more than 16 bytes are received
the oldest bytes get overwritten by the newest bytes
From these comments you can see how important it is to post your COMPLETE code
best regards
Stefan
Is this the correct way to check for -1? When I do this, it just sends empty strings to my computer.
flo,
you are using RxStrTime to receive SINGLE bytes. RxStrTime is for receiving MULTIPLE bytes.
To give you further advice please do me a favor and post how your COMPLETE data-exchange looks like.
Especially how long is the longest command-string?
How do you send the command-string? I mean this: let's assume your commandstring is "START"
From the PC do you send the string "START"+CR at ONCE
or do you send it as single characters?
"S" then there is a pause of 3 seconds
"T" then there is a pause of 0,1 seconds
"A" then there is a pause of 5 seconds
"R" then there is a pause of 1,2 seconds
"T" then there is a pause of 40 seconds
CR then there is a pause of 9 seconds (CR means the DELIMITER-character decimal value 13)
If you send it at ONCE "START" CR
you simply code a
If the boolean expression (MyStr[noparse][[/noparse]0] == 0) is true nothing was received
otherwise you received the COMPLETE string
YOU DON'T have to put together every char to a string. That's what RxStr and RxStrTime are doing already.
If a string-receiving (=bytesequence) has started to come in,
RxStrTime will receive all these characters at ONCE.
So if MyByte[noparse][[/noparse]0] contains something NOT equal to zero it contains already the COMPLETE string, if the string is sended at ONCE
So please post a DETAILED description of your data-exchance and archive and attach your COMPLETE project again
best regards
Stefan