BS2 driven debug window
jgamblain
Posts: 11
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
' {$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
It's still not clear to me how you have one BS2 connected to another.
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.
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.
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.
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.
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.
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.
BTW... on a personal note, good to see someone from the Old Town... I grew up in IGH/SSP :smilewinkgrin:
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.