Basic Serial I/O - program stubs
mindrobots
Posts: 6,506
in Propeller 2
I didn't write most of this, the rcv code is based on Chip MainLoader and the tx code is pretty much from OzPropDev (Brian)'s code. I just packaged them up as little test programs in case anybody wants to do some I/O before they perfect their own.
Simple single character receives and send through the standard com port (RX_PIN = 63; TX_PIN = 62). Baud is set to 115,200.
The "test code" part of the program just does a loopback.
The stub without _hi runs completely in COGEXEC within one COG (COG0 as it is written).
The stub with _hi runs in HUBEXEC with some data in COG0 COGRAM and all the code in High (>$1000) HUBRAM.
I'm sure there will be better but this might get you going with terminal I/O (thanks to Brian and Chip).
They both seem to work. I've only tested on the 1-2-3 board so far.
If you have enhancements/fixes you want to contribute, please post them!
Simple single character receives and send through the standard com port (RX_PIN = 63; TX_PIN = 62). Baud is set to 115,200.
The "test code" part of the program just does a loopback.
The stub without _hi runs completely in COGEXEC within one COG (COG0 as it is written).
The stub with _hi runs in HUBEXEC with some data in COG0 COGRAM and all the code in High (>$1000) HUBRAM.
I'm sure there will be better but this might get you going with terminal I/O (thanks to Brian and Chip).
They both seem to work. I've only tested on the 1-2-3 board so far.
If you have enhancements/fixes you want to contribute, please post them!
Comments
I wonder if I'm seeing this right:
I imagine that setb only takes pin numbers from 0..31. So, sending it #62 gets reduced to reduced to 5 bits, making it #30. Which, happens to work out.
I guess I would think of the pin as B30 instead of #62, but I guess need to think both ways...
Brian and Chip both call them by the 6 bit number but the math does work out. I saw another reference to pin 30 of an outb so we will probably see them both ways.
@ozpropdev did the same trick. It's clever, once you realize that bit 6 is effectively indicating INA or INB. In fact, this would be a good candidate for some alias instructions:
(edit: updated to show mapping.)
(edit: added "GET" aliases.)
I have combined your code with Chip's sin/cos example to transmit the sin/cos values stored in the LUT ram. I am working on a serial graphical utility using Processing.org, which is cross-platform. The skeleton of this works on Window 8.1... I am very interested to know if it will work on other platforms. In the past, the serial libraries sometimes worked on the Mac and sometimes they didn't.
Right now I'm only using the serial libraries of Processing.org. But there is a GUI library(controlP5) here that I will be using as well. This should allow us to load images to the P2 and view contents of HUB RAM as images, and a variety of other ways.
In my set-up the results are viewable in the log window of the serial terminal.
Here is the Processing.org code for the rudimentary serial terminal... called a "sketch":
It doesn't do that, and I don't know why.
If your using PST then the lower byte values $0 to $10 will effect the display.
The code appears to be looping Ok but the random "clear screen" and "cursor position" codes
are giving the illusion of no activity.
Brian
No, I'm using a diy utility. Right now it is serial transmit and receive only, with no bells or whistles. Nothing is being done with the received bytes(yet), except to echo them to a log window.
Processing 3 is from Processing.org and is an open, cross platform development language/system, built on Java but with simplified language constructs. Processing 3 has the capacity to encapsulate code into stand-alone applications. I have listed the "sketch," because I don't have the correct JRI installed (I am afraid to touch my computer right now... so I haven't tried to update it ... and thus I can't generate applications.)
If anyone wanted to try it, they would have to download Processing 3 from Processing.org and then paste my code into the code window. Hit the run button and you should see a terminal, which you click on and hit any key.... after you run the P2 code.
I looked again at the issue that popped up late last night. It turns out that if I leave my terminal on top.. don't go to the desktop for example... it loops just fine. So, you are correct. The looping in the P2 code is working. The issue is on the other side and seems related to how Processing 3 itself relates to the port. I am going to put that problem to the side and work on the interface.
Rich
p.s. Processing 3 has libraries that make it very easy to access the new Kinect V2, which has a very accurate time of flight (TOF) depth camera. ($100 used at GameStop... requires an adapter cable from Microsoft $50). Processing 3 also has libraries for openCV... So, it should be possible ... for example to loiter a quad-copter at ten feet up and have it choose a clear landing site... or find the best path through a cluttered space... or measure all the objects around itself and transmit the juicy bits to a P1 or P2 bot.
I'm using coginit/cogstop to flash LEDs 4..7, like I described in the DE0-nano support thread. This should be ok on other boards too (except it will really start and stop COGs in that case!).
I'm still confused about addresing operators, just hammered on until loopback started to work again.