Serial Object for P2
in Propeller 2
Can someone point me to a good serial in / out object using the P2 with smart pins?
Thanks in advance!
Can someone point me to a good serial in / out object using the P2 with smart pins?
Thanks in advance!
Comments
Check out jm_fullduplexserial.Spin2 by JonnyMac on GitHub.
https://github.com/parallaxinc/propeller/tree/master/libraries/community/p2/All/jm_full_duplex_serial
Thanks!
Here's a really simple serial object that uses smart pins. It only provides basic tx and rx methods. For formatting use SEND together with a formatting object like ers_fmt.
There can be a problem if the sender sends too fast. In this case a circular buffer and a dedicated cog is needed.
The simplest spin solution I used for communication with a RPi Zero:
A serial cog functions:
and init a cog:
cogspin(16,serialcog(),@serialstack)
Now use serialread and if the result is >-1 then you have received a byte. No more bytes lost while a spin code processes the previous byte.
Yes, if the baud rate is high and your Spin code is busy then you have to be careful about reading data, but that's true even if you have a buffer (it just delays the point at which overflow will occur). The smart pin itself acts as a 1 character buffer. which is adequate for many purposes. @evanh posted a clever method for using the smartpin to buffer 3 characters by setting it in 28 bit mode instead of 8 bit mode, which is even better (but depends on the sent bytes being continuous).
If you're going to use a cog for serial then you might as well use a multi-port serial object like @Cluso99 's.
Has anybody done a serial driver that uses a smart pin with an interrupt service routine to handle the buffering? I'm assuming it's possible to get an interrupt when the transmit register is empty, or the receive register is full, is that correct?
There's likely a reluctance for this, it comes with some caveats. eg: Can't use long WAITXs or REPs in the same cog.
I wrote a 2-port serial drive fitting completely in a COG and uses buffer in the LUT, needs some 12 HUB longs for init and then uses 8 of them longs for mailboxes.
if i remember correctly @RossH uses it in catalina and needed to fix something.
https://forums.parallax.com/discussion/169660/cogserial-fullduplex-smart-serial-using-interrupt#latest
and
https://forums.parallax.com/discussion/170101/fullduplexserial2-spin-for-use-with-fastspin-and-the-p2#latest
Mike
Yes, I understand the issue with long latency instructions and interrupts. However, it would be nice to have the option to do this. If I don't have any free cogs it would be useful to have a buffered serial port using interrupts and a smart pin. Maybe the compilers could have a low-latency option which would avoid using WAITX and REP. I recall some discussion about this.
I personally have only been using rx for getting key presses in my hardware testing. I haven't needed significant buffering.
I'm using SmartSerial right now with FlexSpin C and works great.
Only thing I might change is to allow not using either TX or RX pin by feeding a negative pin# value to start().
@Rayman ,
With the serial driver I wrote that is possible since I needed a driver for Parallax Laser Ping and TFMINI Lidar.
Mike
@iseries Where is it? Maybe I'll take a look...