Serial port usage, how?
ypapelis
Posts: 99
I didn't realize something that simple can be so frustrating. I have been trying for hours to figure a way to simply use a serial port. Not one associated with pins 30/31, but with other pins, or possibly multiple sets of other pins. I want to be able to do high speed (115200 or more) baud, full duplex, and possible do it on more than one port using the same driver (like the spin drivers). Rather embarrasing, but I can't figure out how!
There are two posts discussion the serial port and FullDuplexSerial, but both refer to using it for stdio, and focus on non-blocking reads (which I also need to do). There is a post that shows a simple (and probably working) serial port driver. In the demos, there is a full duplex serial - heater version, but it won't compile as is, I believe it was constructed for an earlier version of proggcc. I have seen posts on the FullDuplexSerial 'stdio' driver, but can find nothing in the headers to help use it. There has to be a normal, built-in way of including a header file and calling serialOpen(txPin, rxPin, baud), or something like that. I could have probably written my own in the time it has taken, but I'd rather not at this point. And I am sure, there is a trivial way to do it, but for whatever reason, I haven't found it yet - any pointers would be greatly appreciated!
There are two posts discussion the serial port and FullDuplexSerial, but both refer to using it for stdio, and focus on non-blocking reads (which I also need to do). There is a post that shows a simple (and probably working) serial port driver. In the demos, there is a full duplex serial - heater version, but it won't compile as is, I believe it was constructed for an earlier version of proggcc. I have seen posts on the FullDuplexSerial 'stdio' driver, but can find nothing in the headers to help use it. There has to be a normal, built-in way of including a header file and calling serialOpen(txPin, rxPin, baud), or something like that. I could have probably written my own in the time it has taken, but I'd rather not at this point. And I am sure, there is a trivial way to do it, but for whatever reason, I haven't found it yet - any pointers would be greatly appreciated!
Comments
The underlying code (the FullDuplexSerial code running on a COG) is the same, but the interface is completely different -- spin2cpp will produce an object with methods like "rx", "tx", "str", etc., whereas the FullDuplexSerialDriver interfaces to the C standard libraries so you can use the normal C functions like getchar, putchar, and printf.
Eric
I am trying to use full duplex serial in a C program but I am having a tough time trying to figure out how to do something that was done with the FullDuplexSerial object in Spin.
In Spin we had the rx method which when called would either give us a value of -1 if the buffer was empty or the first byte available in the buffer. This would allow the main program to do other things while data was being sent from another machine. I find however that the getchar function doesn't return unless it has received something from the PC.
Is there something similar to rx in the C implementation of FullDuplexSerial?
Thanks,
Enrique
Hi Enrique,
There was a thread earlier that showed how to do this: http://forums.parallax.com/showthread.php?141659 I have confirmed that this approach works.
And as mentioned in a post above, Spin2Cpp can be used to generate C code from the good-old FullDuplexSerial. Somehow I have not mustered the courage to try this; it just seems so wrong (too complicated for something that obvious). Maybe someone can post the final output files so we can use them directly.
Keep in mind, the approach of including FullDuplexSerial in the stdio driver table and then invoking it through fopen() wastes one COG, since it seems to reserve a cog for stdin, and another cog for every instance of fopen. This is a serious problem is you are using a lot of serial ports, as each one of them will use a different COG. Obex contains a FullDupliexSerial_r004 object that allows up to 4 serial ports at full speed, using only a single COG. It would be nice to have similar functionality accessible in C, without having to resort to stdio interfaces.
Ok, that seems to work. So what exactly is the significance of the _driverlist table, is it a table of available I/O drivers, all of which are available for use through fopen(), and the convention is that the first one will be used for stdin/stdout/stderr?
By the way, is this information listed anywhere? If not, I am sure a wiki page or other full summary of it would save a lot of people a lot of time.
Look here https://sites.google.com/site/propellergcc/documentation/libraries
here http://code.google.com/p/propgcc/ here http://propgcc.googlecode.com/hg/doc/Library.html
and here http://code.google.com/p/propgcc/source/browse/#hg%2Fdoc
Enrique
Have been using your driver for a while, it works beautiful.
Thanks.