Simple Serial for Spin2 with PNut (Updated 15 MAR 2020)
JonnyMac
Posts: 9,104
I am very late to the P2 party, so there may be code that does this, but I couldn't find it. I wanted to do simple serial debugging of Spin2 code compiled by PNut so I cobbled this together from code by Eric Smith and Chip. It uses the core of Eric's SmartSerial (sans autobaud), with formatting routines by Chip and me. Fixed and variable width output for decimal, hex, octal, and binary are supported.
So far everything seems to work, and yet, I'm sure that even this simple code can be improved. When you make fixes/improvements, please share.
Edits:
-- fixed octal formatting
-- added quarternary formatting
-- added formatted strings
-- added demo program
-- fixed bug with fpdec()
-- added generic formatted number output
-- decimal and string fields can now be left- or right-padded
-- updated jm_nstrings library to unify int-to-string conversion with itoa()
-- last update 15 MAR 2020 @ 2:45pm PDT
Notes (discovered moving code from P1 to P2):
-- The Spin1 => and =< operators now match other languages (>= and <=).
-- The Spin2 encod operator works differently than its P1 namesake, |<.
-- The || operator in Spin1 has to be changed to abs in Spin2.
28 FEB 2020
GOOD NEWS! Chip found the issues with if/elseif/else and everything in my format() method for strings is now working as intended. You can, for example, do this:
So far everything seems to work, and yet, I'm sure that even this simple code can be improved. When you make fixes/improvements, please share.
Edits:
-- fixed octal formatting
-- added quarternary formatting
-- added formatted strings
-- added demo program
-- fixed bug with fpdec()
-- added generic formatted number output
-- decimal and string fields can now be left- or right-padded
-- updated jm_nstrings library to unify int-to-string conversion with itoa()
-- last update 15 MAR 2020 @ 2:45pm PDT
Notes (discovered moving code from P1 to P2):
-- The Spin1 => and =< operators now match other languages (>= and <=).
-- The Spin2 encod operator works differently than its P1 namesake, |<.
-- The || operator in Spin1 has to be changed to abs in Spin2.
28 FEB 2020
GOOD NEWS! Chip found the issues with if/elseif/else and everything in my format() method for strings is now working as intended. You can, for example, do this:
x := 15 term.fstr5(string("%3d %3x %3o %3q %4b\r"), x, x, x, x, x)...which gives you this:
15 F 17 33 1111
Comments
Problem fixed.
Ahh, I see attachments are missing. Will summon the web gurus.
EDIT: I attached your original file as test.
Should be working now, Jon.
PNut
Access violation at address 00461E54 in module 'PNut_v33L.exe'. Read of address 02793000.
OK
??
I guess the one drawback here is that there is no big receive buffer, right?
But, I'm usually doing a lot more transmitting that receiving... So, maybe doesn't matter to me...
Still, this may be a case where using interrupts may be useful in certain cases...
How many bytes can come in before you lose data if you don't check on receive buffer?
Latest flexgui (fastspin compiler v4.1.3) fails to build the demo: It does not like: ||= PNut_v34i, compiles without issue.
An issue for fastspin?
dgately
That said, the segment is a mouthful of code -- typical of Chip's style <grin>
I suppose it could be simplified to
Eric does intend to make Fastspin/FlexGui able to compile the official Spin2 syntax. It'll just take some time and Chip's documentation of Spin2's full syntax.
Does mimic FastSpin's serial STD but also has async handling.
Have not tried it with spin2,works with FastSpin.
Mike