Shop OBEX P1 Docs P2 Docs Learn Events
BS2 driven debug window — Parallax Forums

BS2 driven debug window

jgamblainjgamblain Posts: 11
edited 2010-09-03 12:27 in BASIC Stamp
I am trying to create a device that when plugged into the DB9 of the BS2 carrier board, it displays debug info on a built-in LCD. Kind of like a portable debug window. I have gotten it to the point where it will take any char I type into the debug window on the PC, and correctly display it on the LCD. The problem I am having is when I hook it up to another BS2, it displays the correct amount of characters, just garbage. Is this a timing issue, or do I need to write a routine that if "Hex input = this, then output this ASCII character". I was under the impression that the BS2 would output raw ASCII codes, so no conversion is needed. Here is my source for reference. Oh... I am also using the Newhaven Display NHD-0220D3Z-FL-GBW. It is a neat little setup that you can configure for RS232, I2C, or SPI, and does all the conversion automatically to the standard Hitachi driver chip.

' {$STAMP BS2}
' {$PBASIC 2.5}

'
' SCOPE
'
'
' CREATE A DEVICE FOR DISPLAYING DEBUG INFORMATION ON AN LCD SCREEN
'
'


'
' CONSTANTS
'
LCD232 PIN 8


'
' VARIABLES
'
POS VAR Word 'VARIBLE FOR CURSOR POSITION
CONT VAR Byte 'VARIBLE FOR LCD CONTRAST (1-50 DEC)
BL VAR Byte 'VARIBLE FOR LCD BACKLIGHT BRIGHTNESS (1-16 DEC)

char VAR Byte 'VARIBLE FOR CHARACTER IN FROM DEBUG TERMINAL
cnt1 VAR Byte 'COUNTER 1 FOR LINE 1 CHAR MAX
cnt2 VAR Byte 'COUNTER 2 FOR LINE 2 CHAR MAX


'
' INIT
'

SEROUT LCD232, 84, [$FE, $52, 29] 'SET LCD CONTRAST
SEROUT LCD232, 84, [$FE, $53, 16] 'SET LCD BACKLIGHT BRIGHTNESS
GOSUB LCDCLR
GOSUB LCDBON


'
' MAIN LOOP
'
DO

FOR CNT1 = 1 TO 20 'COUNT CHARS FOR LINE1
DEBUGIN char 'STORE DEBUG INPUT
SEROUT LCD232, 84, [char] 'OUTPUT THIS TO THE LCD
NEXT 'FILL THE LINE

CNT1 = 0 'RESET LINE COUNTER
POS = 8 'SET LINE 2 POSITION
GOSUB LCDPOS 'CHANGE TO LINE 2

FOR CNT2 = 1 TO 20 'COUNT CHARS FOR LINE2
DEBUGIN char 'STORE DEBUG INPUT
SEROUT LCD232, 84, [char] 'OUTPUT THIS TO LCD
NEXT 'FILL THE LINE

CNT2 = 0 'RESET LINE 2 COUNTER
GOSUB LCDCLR 'CLEAR THE LCD, RETURN HOME

LOOP


'
' SUBROUTINES
'
LCDPOS:
SEROUT LCD232, 84, [$FE, $45, DEC POS] 'SET POSITION OF LCD TO MATCH POS VARIBLE
RETURN

LCDBON:
SEROUT LCD232, 84, [$FE, $4B] 'TURN ON BLINKING CURSOR
RETURN

LCDCLR:
SEROUT LCD232, 84, [$FE, $51] 'CLEAR LCD & RETURN CURSOR HOME
RETURN

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-23 10:06
    You should find link to your display's documentation and post it (rather than expecting someone to search for it). Maybe there's a problem with signal polarity. Given that you're seeing the number of characters that you're sending, the Baud is probably correct, but, without the documentation, it's hard to say. How do you have the display hooked up to the 2nd Stamp? Remember that the DB-9 connector is intended to work with RS232 signal levels. If you try to hook it up to other I/O pins, you may damage the 2nd Stamp.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-23 10:38
    Yeah sorry about that. Here is the Data sheet. Yes, I have no jumpers soldered to the display in the R1 or R2 position, denoting the RS232 input scheme. I am using the DEBUGIN command to fetch directly from the DB9 of the Carrier board, and I am outputting to the LCD on Pin8 of the stamp, with no level conversion, since the display accepts 5v RS232 signals, so there is no need for level shifting circuitry.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-23 11:47
    It looks like the display's RX input is indeed compatible with a Stamp's I/O pin with 2.4V or above being a logic 1 and below 2.4V being a logic 0 and a Baud code of 84 should work.

    It's still not clear to me how you have one BS2 connected to another.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-23 12:16
    Here is the scenerio:

    I have a BS2, let's call it BS2_a running in a device with a fairly large and complicated switching array, capable of handling up to 3Kv AC. On the front of it, I have the Programming port for easy access to debugging, firmware updates, Etc.

    What I am trying to make is a small-ish device that uses another BS2 (let's call this one BS2_b), and the Newhaven Display. All I want is any Debug info that is sent out of BS2_a to be recieved by BS2_b through a male to male DB9 cable, and then output on the LCD.

    The reason for this is it is not easy to always bring the whole BS2_a unit over to a computer just to see if there is a simple connection error. The unit hooked up to BS2_a uses all of the IO pins already, so there is no room to just hook the display up to it and be done with the whole mess.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-23 12:40
    The problem you're running into is that the BS2 DEBUG output circuitry is not quite RS232 compatible. In particular, it uses the serial input as a pull up source for the serial output. Look at the schematic for the BS2 module around the SIN / SOUT connections. The solution is to add a pullup resistor to +5V on your debug display RX input. A 1K or 2.2K resistor should do.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-24 06:35
    First off, I want to add that I put in a small amount of code into BS2_b's init section. It just displays what it is, and then the version number of the Firmware, then pauses 3 secs, then clears the display and begins the main loop.


    SEROUT LCD232, 84, ["BS2 Debug Display"]
    POS = 8
    GOSUB LCDPOS
    SEROUT LCD232, 84, ["Version 0.3"]
    PAUSE 3000
    GOSUB LCDCLR

    This tells me that the device is executing code the way it should. Now, on to the results....

    I connected both of the suggested values (one at a time of course) to BS2_b's SIN and VDD pins, one with a 1k resistor, and because I do not have a stock of 2.2k's (looks like I need another digikey order), I used 2 4.7k resistors in parallel to give me roughly the other value. I had no joy whatsoever. It would work when I connected the setup directly to the RS232 port on the computer, and used the debug window, but only after I re-set it. Then, I tried it after connecting it to BS2_a, it would not even boot up BS2_b, and give me the init display.

    Is there another value I should try, or should I dive into re-writing the code to use SERIN on pin 16, instead of DEBUGIN? Or maybe some other plan of attack?

    Thank you for all of your help, I do appriciate this. When it is up and running, it will be one heck of a time saver for me, and I imagine it could become a very usefull tool for other folks out there. I know I would like to build one of these for my hobby stuff at home, and possibly porting the idea over to the BS1, to save a bit of dough on the uC.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-24 07:35
    Your comment about the BS1 got me thinking some more, unfortunately coming up with a significant problem and maybe an answer to what you're seeing ...

    None of the Stamps have any buffering for serial I/O and the BS1 is even slower than the BS2. Debug output is done at 9600 Baud and there are no pauses between characters (and just one stop bit). Although you don't have much code in your program, you've got a lot of SEROUT statements which, at 9600 Baud, take about 1ms for each character to execute. I don't know how you're testing it, but you're probably typing on the keyboard on your PC so there's lots of time for each character for your Stamp to do the processing. When the data comes from your other Stamp, there are no delays and your display Stamp misses characters ... all the time.

    There are solutions ...

    One would be to use a serial input buffer chip like this one.

    Another solution would be to use something like the Propeller Backpack. It comes ready-to-go as a display for Stamp debugging used with a little portable TV or you could modify it to use your LCD.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-24 09:39
    I was afraid of that, and tried to keep the code as simple as possible, to try and get away form a problem like this. You are right, I am entering info by hand in the debug window, so it would make sense that it is a timing issue. So, I am going to order the RSB6505. I peeked at the data sheet, and I see that I will also need the MAX232 level shifter, and that is not a problem, since I have a few on hand.

    Maybe with all of this, I would have the processor time to handle special-case characters, like the carriage return, and force it to the next line of the display.

    Once I get this guy in I will give it a whirl, and see what happens. I will definitely keep ya posted. I only have one question right now. Am I correct in assuming I would no longer need the pull up resistor to SIN then?

    And once this deviceticle is completed, I will of course be posting a full schematic, parts list, and source code in case anyone else out there is in need of something like this.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-24 17:05
    You won't need the pullup resistor on SIN, but you'll need to use the other side of the MAX232 (transmit to BS2_a) to provide the same source of default voltage to BS2_a. Wire the input to the transmit side with a logic low (0) which is the proper idle state. The MAX232 will invert this and translate the voltage to roughly +9V.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-26 06:44
    Ahh yeah thanks for the reminder... I had not thought that out in the schematic yet (still have not drawn it up), and that brings me to my next point....

    Is Protean still an active distributor? We have called them a couple times, left a voice mail, and have gotten no callback. Our purchasing lady just sent out an email bright and early this morning, hopefully they at least check that. Unfortunately, I have not been able to find this thing anywhere else. From the photos, it looks simply like an in-house programmed PIC of some kind that they wrote some tricky code for.

    If they do not reply, I am afraid we are going to have to dig into another option. I found the MAX3100, but that seems to be not as good of a fit. I am seeing it only has an 8 word buffer to it, and I hope that is enough. This time, I will attach the data sheet for you to peek at, if you get a chance.

    I want to keep this project to a bare minimum of parts and labor designing and building it, since it is just a convenience tool.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-26 07:14
    A MAX3100 would work although the 8 character buffer may not be enough at 9600 Baud.

    I'd seriously consider using a Propeller. If you don't want to mess with a little LCD TV as a monitor, you can use serial LCDs very easily. A Propeller Protoboard is cheap and comes with voltage regulators. You can easily mount a small LCD to it and interfacing to a Stamp's DB-9 connector would only take a couple of resistors. There's plenty of existing code in the Propeller Object Exchange for interfacing to various LCDs or TVs and the Stamp serial port and you can use a serial buffer as large as 512 bytes with some of the serial drivers.
  • jgamblainjgamblain Posts: 11
    edited 2010-08-26 07:30
    Yeah I am thinking I may need to get another uC under my belt... I'll give Protean until the end of tomorrow, then it is off to St. Propellersberg I go.


    BTW... on a personal note, good to see someone from the Old Town... I grew up in IGH/SSP :smilewinkgrin:
  • jgamblainjgamblain Posts: 11
    edited 2010-08-27 10:18
    Prop beginner kit on order. should be here tue. or Wed of next week, then the time to learn the differences between that and the BS2... looks a bit the same so it should not take long to get the hang of it.

    Yeah we have dropped faith in Protean because they simply refused to take our order, by phone or email. Kind of a bummer because I already got the Xtal, Caps, resistors, all of that for the first plan.. oh well, guess I will just have to consider myself more prepared for later.
  • jgamblainjgamblain Posts: 11
    edited 2010-09-03 12:27
    Yep I have the kit and all the trimmings... going through the fundamentals book right now. seems like one heck of a canidate... and I am already liking the structure of this thing. I am going to retire this thread (in my mind anyhow) for now... continue in the Propeller threads if I have any questions or problems. thanks again for your help Mike.
Sign In or Register to comment.