Shop OBEX P1 Docs P2 Docs Learn Events
Fun With Serial Ports — Parallax Forums

Fun With Serial Ports

firestorm.v1firestorm.v1 Posts: 94
edited 2006-08-09 01:28 in BASIC Stamp
I'm working on building a BS-2 equivalent of the Matrix Orbital series LCD displays however I've hit a wall and need to know if this is a programming limitation or if it's something I have coded.

Here's the rules of the program:
Commands start with a 0xFE (254) and are followed by the actual command and any optional parameters.
Example:
(all numbers are their Decimal equivalents, actual commands are sent in HEX and are doded as such.)

254,88 'Clears display and homes cursor
254,74 'Turns on LCD underline
254,71,4,12 ' Moves cursor to 4'th row, 12th line.
etc..

I wrote a quick little app that reads a char from the serial port (using port 16 because I can't afford the MAX232)
and prints some basic info on it. I would expect that it would read each character from the serial port but instead it only reads one.

Here's the app:
'{$STAMP BS2}
'{$PBASIC 2.5}
char VAR Byte
DO
SERIN 16, 16468, [noparse][[/noparse]char]
DEBUG "Char received '",char,"'",CR
DEBUG "DEC = ",DEC CHAR,CR
DEBUG "HEX = ",HEX CHAR,CR
DEBUG "BIN = ",BIN8 CHAR,CR
LOOP
END

I would expect that (254)H would show:
Char received ' '
DEC = 254
HEX = FE
BIN = 11111110
Char received 'H'
DEC = 72
HEX = 48
BIN = 01001000

but instead all I get is the info about the first character (char 254)


Any suggestions as to why the BS2 never picks up the "H"? I read in the PBASIC syntax guide in SERIN that there is no serial buffer in the BS2, Is this what is happening and the lack of a buffer is causing the problem? Is there a way to add one? Would using a MAX232 help this problem?

Thanks in advance.

FIRESTORM_v1

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-08 16:05
    1. I would suspect that the "matrix orbital display" would accept a TTL-level RS-232 signal. In which case, you don't need the MAX232.

    2. If you DO use the "port 16" debug port, anything sent TO the BS2 will be echo'ed back FROM the BS2. You have to allow for this.

    3. If you DO use the "port 16" debug port, then you probably shouldn't use the "DEBUG" output at the same time. This port uses the 'RX' line voltage in the 'TX' signal back out from the BS2 (that's why there's the echo).

    4. You CAN have the BS2 recieve (SERIN) serial data on any pin, IF you put a 22 Kohm resistor in series with the signal. You may have to tweak the 'Invert' baud mode.

    5. If you use "SERIN 16, 16468, [noparse][[/noparse]MyChar]", then you have told the BS2 to read a single character. You need
    "SERIN 16, 16468, [noparse][[/noparse]STR MyStr]" to read an entire string. (Where MyStr is declared as "MyStr VAR BYTE(10)")

    OR, you could use SERIN 16, 16468, [noparse][[/noparse]DEC Sync, DEC Byte1, DEC Byte2, DEC Byte3, DEC Byte4]

    The "DEC" modifier here will tell the BS2 to read a decimal number string, convert it to a 'number', and stuff that 'number' into the following variable.· This saves memory space on your BS2.
    ·
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-08-08 16:19
    Actually, I have great news! I just got an email and TI is going to send me a Max232 for free! (yay free samples)

    That should clear up the port 16 issues quite nicely. [noparse]:)[/noparse]

    About point #5:

    I was thinking that the BS2 would read the first character and then swing about and ring the 2nd character after it prints the lines. Do I need to add a serial buffer to take care of this issue or will I need to just read in blocks of 20 each time?
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-08-08 16:22
    The MO display I'm working on recreating is the PK202-24-USB (with most commands regarding Keypads, Bar graphs, GPO's and Fans not implemented. Details here: http://www.matrixorbital.com/product_info.php?pName=pk20224usb
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-08 18:07
    1. You probably do NOT want the "USB" version of the Matrix Orbital module. I believe that version requires a PC to act as a 'USB Master'.

    2. The non-USB versions of the Matrix Orbital modules appear to have a jumper, which will let you select what they call "RS232TTL". This is the RS232 protocol, done with TTL voltages. That's what the BS2 wants, and means you don't have to insert the MAX232 in the circuit.

    3. You can use a 'time-out' on your SERIN, with a DEC modifier on your parameters, to get the data. It's not clear at this point if you intend the BS2 to be a 'stand-in' for the display?

    -- Reading further, it DOES look like you're trying to use the BS2 as a 'replacement' for the Matrix Orbital module.· So yes, things would be much easier with a 'second' serial port using the MAX232 to talk to the PC as if the BS2 were a Matrix Orbital module.

    Oh, and the reason the BS2 only gets the first character is that the BS2 has no serial buffer.· If the BS2 is·not sitting in a SERIN command, waiting for data, any data that arrives gets ignored.· Thus, your "DEBUG" output statements take so much time, that by the time the BS2 gets back to read another character, the whole message has already gone by.

    The DEC modifier gets the BS2 SERIN command to 'wait' for a full number before returning.· Even then, if you want 4 numbers, you need to have 4 DEC clauses.


    Post Edited (allanlane5) : 8/8/2006 6:12:05 PM GMT
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-08-08 18:17
    You are correct. I can't afford the $70.00 MO display, have a 4x20 display hanging around that someone bought me, got creative and poof, here I am.. [noparse]:)[/noparse]

    Hmm, that could kill the project. I know that I would have a max of 24 characters at any given time, but I think I would run out of variable space. [noparse]:([/noparse] You wouldn't have any suggestion for conserving variable space, would you?
    I should be using Byte, not word, correct?

    I'm still excited about the MAX232s and am glad that I get those to play around with.

    Thanks for the help, hopefully I can find a solution.. [noparse]:)[/noparse]
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-08 19:30
    Well, if you use the DEC modifier, then four or five characters ("254,") get converted into a single byte value 254. That's the the easiest way to conserve variable space. Plus you could use a 'WAIT' parameter for the 0xFE, so you wouldn't have to store it at all.

    It also depends if you can put delays between the bytes being output. If it were possible for the BS2 to get one byte, make a decision, then enter another SERIN statement BEFORE the PC sent the next byte, all kinds of space-saving stuff becomes possible.
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-08-08 19:52
    Good question on that, I'm using LCD Smartie ( http://www.lcdsmartie.org ) as the source for the RS-232 output. I have seen other people doing this with a PIC microcontroller, but I know next to nothing about PICs and I don't have one.. [noparse]:([/noparse]

    I don't think that it would be possible to insert any pauses into the output of the signals, making it even harder.

    So, anyone know how to add a serial buffer to the BS2?

    Thanks for the help everyone. [noparse]:)[/noparse]
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-09 01:28
    http://www.rhombus-tek.com/co-processors.html

    The 'SMT' co-processor chip includes a serial recieve buffer. It's kind of limited -- 8 bytes? But it should fulfill what you're looking for.
Sign In or Register to comment.