Two Serial Ports
mynet43
Posts: 644
Would someone please post some code showing how to use two serial ports at the same time?
I have one port with Rx, Tx on pins P12 and P13.
The other port has Rx, Tx on pins P14 and P15.
I'm familiar with using the serial routines like FullDuplexSerialPlus, etc. I've just never done two ports at once.
Thank you for your help.
Jim
I have one port with Rx, Tx on pins P12 and P13.
The other port has Rx, Tx on pins P14 and P15.
I'm familiar with using the serial routines like FullDuplexSerialPlus, etc. I've just never done two ports at once.
Thank you for your help.
Jim
Comments
I'll check that out.
It sounds like it's just what I'm looking for.
Jim
I often have a serial connection monitored in a separate cog.· This isn't the most efficient way to do this but it's easy for me to understand what is going on.
There are several refinements I left out for clarity.· In this example I left the names of the devices I use (barcode & balance).· This object only receives data from the serial connections and assumes data terminates with a carriage return.· You'd want to use a different solution if you also want to send data over the lines(such as FullDuplexSerial).
I'm using simpleSerial since I am "watching" the serial line a separate dedicated cog.
If you use FullDuplexSerial you wouldn't need to start new cogs to watch the serial ports since FullDuplexSerial·runs in·its own cog anyway.· Just use rxcheck in the main loop to check for new received bytes.
Hopefully·some of this will be useful to you.
I haven't been able to get the 4 port serial object to work for me.· I think one of the methods I was using wasn't behaving well and keep the 4 port object from working.
Duane
Thank you for the example and your note about the 4-port serial interface.
I've downloaded the 4-port serial code and I plan to test it in the next couple of days.
I plan to run a loopback test, something like his sertest.spin. If this works, I think I'll be OK.
Thanks again for your help.
Jim
Duane, what was the problem you had? I do have an updated version but it adds a couple of advanced features rather than fixing any bugs.
Thanks for checking in on this.
A couple of questions, since I haven't tried it yet.
1. In your sertest.spin program, you use the constant NOMODE for the input mode parameter. Is this the correct constant to use for standard serial output?
2. In the same program you're using pcFullDuplexSerial as the debug serial program. This isn't included in your zip file. It looks like a single port version because the calls only have one argument. I'm using FullDuplexSerialPlus for the debug routine. Is there an advantage to using the 'pc' version?
3. Do you have a routine like 'getstr' in FullDuplexSerialPlus, or do I need to supply my own?
My goal is to support two standard RS-232 I/O ports for both input and output. It looks like this should work fine.
Am I on the right track?
Thank you for your help.
Jim
Thanks for the great answers. I think I'm off and running.
Do you plan to put the getstr( ) routine in the code? If not, I'll probably stick it in my copy of your program. Or it wouldn't be much trickier to put it in the calling program.
I also noticed you have a getc( ) entry that does the same thing as 'rxcheck', so I may use that.
Final question. In the sertest routines, I noticed you use a second object for the debug port. Would it also work to use one of your multi-ports and just assign it pins 31 and 30 in the AddPort call?
Thanks again for all your help. You've made it much easier to get started.
Jim
I doubt my problems were do to your object.· I was using an early version of Kye's SD card object (Kye has since stated it was full of bugs) and I'm guessing it didn't play nice with your object.· I had other troubles with the early SD object but I got it to work (I had to move some of my variables declared in a DAT section to the VAR section).· I plan on trying the four port serial object again with Kye's updated object.· It would save me several cogs (I'm always running out of cogs).
Duane
Re
shoud that be "== 0" if you are looking for a zero terminated string? Or are you looking for a zero terminated string that ends in 0,13?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
I've been playing with it.
I added the code for getstr( ) to the driver and it works perfectly with the PST.
I wrote a test case to input from and output to the PST, using port 2.
I've attached the modified pcFullDulplexSerial4FC with the getstr( ) routine. I may remove this and put it in the calling routine.
Anyway, here's the test case. I'm running it on a demo board with a mouse attached. Everything works great!
Thanks for all the help.
Jim