Shop OBEX P1 Docs P2 Docs Learn Events
DEBUGIN, DEBUG miscommunication? — Parallax Forums

DEBUGIN, DEBUG miscommunication?

lednakashimlednakashim Posts: 2
edited 2013-11-19 08:31 in BASIC Stamp
I'm trying to get a simple echo program working to debug the communication errors in my larger program.
' {$STAMP BS2}
' {$PBASIC 2.5}
val Byte Word
MAIN:
  DEBUGIN val
  DEBUG  val
GOTO MAIN

For slow single digit input this program works, but when I try to copy and paste a paragraph into the terminal I get out a lot of garbage.
Using a terminal (termite) if I transmit the following text
Lorem ipsum dolor sit amet, vidisse mandamus eum cu, no nec graece iracundia. Eu mea quod wisi, stet deleniti te mei. Modo praesent qui eu, quando luptatum conclusionemque quo cu. Graeci verear adipisci id per, option complectitur ius ea.
I get out
L[0F]re-@ip[03]um dolkr †it[00]am!t,[00]pi$iss m!nd[01]Úu#@e5Ò caX [0E]Ò nAc [03]äa%Æe ÒraÆun€ia* E!@m%a q!Þd[00]îi#i, [01]te @d[05]Ðe.Òti@te Úe)T M)do prAÂseÔt [02]ui eu,@q5Ând[0B] l[01]pt[01]èu-@coÔcl[01]si/je-Âue@qu+@ceT G`Âe#Ò [06]ÂreÂr [01]Èi iscÒ i  p[05]ä,     pt    Þn[00]com le#èi$qr ’us@ea*þ

My serial settings look like:
serialsettings.png
521 x 273 - 29K

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-11-17 16:44
    First of all, the code you posted probably won't compile because of the "val Byte Word". That needs to be "val var byte".

    Regarding the errors, remember that the BS2 is not very fast. DEBUGIN and DEBUG operate at 9600 Baud and the setup time for each of those statements is at least several hundred microseconds, enough for the DEBUGIN to miss a character often which is what you're seeing. You're probably not going to get this sort of loop to work over 2400 Baud which you can use by using SERIN and SEROUT instead of DEBUGIN and DEBUG. SERIN and SEROUT can be used with port 16 which is the PC port although data sent from the PC to the BS2 will be echoed back to the PC just like with DEBUGIN and DEBUG.
  • lednakashimlednakashim Posts: 2
    edited 2013-11-18 13:46
    Yeah, but I can't ge tit work even at 2400 Buad,
    For example,
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    val VAR Byte
    '84 is 9600
    '396 is 2400
    BAUD CON 396
    DELAY CON 10
    MAIN:

    SERIN 16, BAUD, 10000, MAIN, [val]
    SEROUT 16, BAUD, DELAY, [ val]

    GOTO MAIN
  • Mike GreenMike Green Posts: 23,101
    edited 2013-11-18 16:13
    Sorry, I may have mislead you in that your program won't work at all at any Baud. The problem is that neither input nor output is buffered. While the program is echoing one character back to the device, it's not listening to the input line, so the best you can do is echo every other character. Solutions include using an external buffer chip like those made by ProteanLogic or using something like a Propeller which can do several things at once.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-11-19 08:31
    It depends too on how much control you have over the PC end of the connection. Some terminal programs have a pacing option, that is, a delay inserted between each character sent. You would need a delay equal to the width of a character, to allow the Stamp time to execute the DEBUG, to retransmit the character it has just received with DEBUGIN. At 9600 baud, allow 2 ms between characters. Your terminal config screen from post#1 does not show a pacing option. That would be equivalent to having 10 or 20 stop bits, but that high a number is usually not available on the stop bits menu. If on the other hand you are writing your own program on the PC end, then pacing does become an option. Another option is flow control (RTS/CTS), and that might help if also implemented on the PC so that it transmits to the Stamp only when the Stamp is sitting on the SERIN command. An interface can be implemented as command/response so that everything happens when both sides are ready. The Stamp does have serial input options that can receive short strings of data well at 2400 baud, but during the receiving the Stamp can't do anything else. All workarounds!
Sign In or Register to comment.