View Full Version : PropBasic, Viewport and Spin interoperabilty?
11-02-2011, 07:26 PM
PropBasic and Viewport play together quite nicely, thanks to the authors! I'm trying to add a Spin based ADC driver into some working PropBasic code via the Spin dispatcher technique outlined in the main PropBasic thread. the problem I'm encountering is that while the code compiles it will not successfully load - Viewport gives the error dialog stating "Failed to configure on COM2". If I comment out the Spin dispatch code all is well. I'm obviously missing something very basic. Attached is the non-working PB code with the Spin dispatch code active, the generated code and the driver referenced in the dispatcher.
11-02-2011, 09:12 PM
I wasn't able to compile because I'm missing some files: "wheelsignal", "decoder" and "inj_1"
However, I think I've found the problem- you call
Coginit(1,@__Init, @__DATASTART) in your "spinstart" method. Cog 0 runs the main spin program. Before calling your SpinStart method, PropBasic starts the conduit object- which then runs in Cog 1. You then overwrite that cog with your method- so ViewPort isn't able to connect!
Let me know how you go- either change to the "cognew" call or load into a different cog.
11-02-2011, 09:31 PM
I figured I was stomping on conduit somehow - I've already tried cognew and coginit with other specified cog IDs, no change. The missing files will be generated by PropBasic when you compile vptest.pbas. They are .spin files generated for each task present in vptest.pbas. I tried killing all references to Viewport to no avail, there's still a bunch of VP specific code generated by PB. I also tried loading to RAM/EEPROM without VP support from VP's Run command (Shift-F3 & F4) and a reference to VPWatch is still generated:
PUB __Program | __VarsPtr 'PROGRAM MAIN
__VarsPtr := 0
CogInit(0, @__Init, __VarsPtr)
Here's a version that will compile due to the spin dispatch being commented out:
11-02-2011, 10:03 PM
I got it!
In order to use ViewPort, the Conduit object must be running in a cog. If you don't start it, overwrite it, or conflict with the pins it uses (30,31)- then ViewPort won't be able to communicate with the Propeller.
You're not starting it!
The vptest.spin has 2 spin methods- "__Program" and "SpinStart". Since "SpinStart" is first, it will execute- but it never calls "__Program"- so vp_config never gets called.
Fixing the vptest.spin is easy, either move the "__Program" method to the top, or call "__Program" from "SpinStart".
I haven't been able to move things around in the "pbas" file to get the PropBasic compiler to do the right thing. Ideally, the PropBasic compiler should ensure that user code is always placed below PropBasic intialization code...
11-02-2011, 10:18 PM
Hanno, thanks so much! It now compiles and seems to work correctly after I manually moved "SpinStart" below "__Program" in the generated .spin file. I'll fool with various approaches in the .pbas file to see if the compiler can place things in the correct order. Hopefully Bean will see this thread and clarify as to the best way to make this work with PB. Again, thank you!