problem with SXB serial communication & VB2005 GUI
Fry'n ICs
Posts: 11
Greetings!
I have been experiencing a lot of trouble with the SERIN command in SXb and am hoping that someone can offer some insight.
__________________
The problem:
__________________
I am attempting to send a byte from Visual Basic 2005 to an SX chip. The SX is attached to 8 LEDs which display the byte value in binary. If this sounds familiar, it's because it's from the SX help file. Everything seems to work fine for bytes 0 thru 127. But as soon as I hit 128 and higher, I start getting unpredictable output on the LEDs.
__________________
The circuit:
__________________
1) SX chip on a parallax professional development board plugged into the designated SX socket.
2) 8 LEDs attached to pins RC.0 thru RC.7
3) RA.1 attached to pin 3 (SIN) on my computers serial port. (see attached schematic showing serial connection.)
__________________
SX Code:
__________________
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
'
' IO Pins
'
RX PIN RA.1 INPUT 'This pin recieves the byte from the computer
LEDs VAR RC 'Prepare the LEDs to output the byte
TRIS_LEDs VAR TRIS_C
'
' Variables
'
sData var byte 'This variable stores the byte sent from the computer
' =========================================================================
PROGRAM Start
Start:
TRIS_LEDs = %00000000 ' make LEDs outputs
sData = 0 'start with all LEDs off
Main:
SERIN RX, N38400, sData 'get the byte from the computer. The help file says 38400 is the fastest rate available at 4mhz
'Yet even slower rates such as 2400 won't work
LEDs = sData 'output the byte to the LEDs
Goto Main 'rinse and repeat
__________________
The VB2005 code:
__________________
1) Create a new project.
2) drag a serial port control from the tool box to the window
3) Keep all the properties set to default, except change the baud to match the SX code (38400) and set the comport to the right value
4) Drag a button and a textbox control to the window.
5) Double click the button and enter this code:
SerialPort1.Write(Chr(TextBox1.Text))
__________________
Theory of operation:
__________________
Run the VB2005 program, enter a number (zero to 255) in the text box, and click the button. VB converts the number to the corresponding ANSII character and sends it to the SX chip. The sx recieves the character in the form of a byte and outputs the numerical value to the LEDs. Once you get to 128 (and all numbers greater), however, all you get is "63" output to the LEDs (well... the binary equivalent to 63, that is)
I have created extravagant workarounds to resolve this problem... but those solutions are exceeding complicated, slow, and eat up all the memory in the SX that I would rather use for other code. If anyone could tell me what I'm doing wrong, it would be greatly appreciated [noparse]:)[/noparse] If what I am trying to do isn't possible, a less complicated solution would also be appreciated. The SX needs to be able to count from zero to 255 (all LEDs off, to all LEDs on).
Thanks!
I have been experiencing a lot of trouble with the SERIN command in SXb and am hoping that someone can offer some insight.
__________________
The problem:
__________________
I am attempting to send a byte from Visual Basic 2005 to an SX chip. The SX is attached to 8 LEDs which display the byte value in binary. If this sounds familiar, it's because it's from the SX help file. Everything seems to work fine for bytes 0 thru 127. But as soon as I hit 128 and higher, I start getting unpredictable output on the LEDs.
__________________
The circuit:
__________________
1) SX chip on a parallax professional development board plugged into the designated SX socket.
2) 8 LEDs attached to pins RC.0 thru RC.7
3) RA.1 attached to pin 3 (SIN) on my computers serial port. (see attached schematic showing serial connection.)
__________________
SX Code:
__________________
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
'
' IO Pins
'
RX PIN RA.1 INPUT 'This pin recieves the byte from the computer
LEDs VAR RC 'Prepare the LEDs to output the byte
TRIS_LEDs VAR TRIS_C
'
' Variables
'
sData var byte 'This variable stores the byte sent from the computer
' =========================================================================
PROGRAM Start
Start:
TRIS_LEDs = %00000000 ' make LEDs outputs
sData = 0 'start with all LEDs off
Main:
SERIN RX, N38400, sData 'get the byte from the computer. The help file says 38400 is the fastest rate available at 4mhz
'Yet even slower rates such as 2400 won't work
LEDs = sData 'output the byte to the LEDs
Goto Main 'rinse and repeat
__________________
The VB2005 code:
__________________
1) Create a new project.
2) drag a serial port control from the tool box to the window
3) Keep all the properties set to default, except change the baud to match the SX code (38400) and set the comport to the right value
4) Drag a button and a textbox control to the window.
5) Double click the button and enter this code:
SerialPort1.Write(Chr(TextBox1.Text))
__________________
Theory of operation:
__________________
Run the VB2005 program, enter a number (zero to 255) in the text box, and click the button. VB converts the number to the corresponding ANSII character and sends it to the SX chip. The sx recieves the character in the form of a byte and outputs the numerical value to the LEDs. Once you get to 128 (and all numbers greater), however, all you get is "63" output to the LEDs (well... the binary equivalent to 63, that is)
I have created extravagant workarounds to resolve this problem... but those solutions are exceeding complicated, slow, and eat up all the memory in the SX that I would rather use for other code. If anyone could tell me what I'm doing wrong, it would be greatly appreciated [noparse]:)[/noparse] If what I am trying to do isn't possible, a less complicated solution would also be appreciated. The SX needs to be able to count from zero to 255 (all LEDs off, to all LEDs on).
Thanks!
Comments
[noparse][[/noparse]Edit] I've attached a demo program that works. I had to use HyperTerminal to test it as I don't have VB2005.
Post Edited (JonnyMac) : 1/1/2009 1:06:36 AM GMT
Dim sdata(1) As Byte
sdata(0)=(Val(TextBox1.Text))
SerialPort1.Write(sdata,0,1)
If you don't yet have any resonators handy the above may still work well enough at internal 4MHz so you can do a little testing until you get one.
Jeff T.
Write,WriteLine and Read,ReadLine in·VB·will easily transmit and receive an ASCII string , to transmit and receive single or multiple byte values in the range 0-255 you need to format Read or Write as we did and set up a byte·array (in our case it was an array with one byte element) and reference the array by an offset and number of bytes to read/write. Not only is this easier to deal with at the SX it greatly improves the data exchange speed.
good luck with the gui
Jeff T.
The attachment has both the VB and the SX code, in VB all that is needed is a Windows Form with two text boxes and two track bars set to a maximum of 255. The program was run on an SX 28 with 50 MHz resonator, adjust to suit.
Jeff T.
The Visual Basic to SX was similar to something I would use with a BS2, I was really pleased with the way in which the two programs interacted, very fast very smooth. The VB code also was not well structured but served for the example.
My next shot will be much improved.
Thanks
Jeff T.
The program may be a little advanced from your point-of-view now, but as you study it (I always try to code cleanly and use good comments) it should start to come together.
BTW... most of the assembly segments that are in the program I learned from exploring the code generated by the SX/B compiler. One final note: the framework is intended for the SX20 and SX28 -- it would require updates to the transmit UART for the SX48.
Jeff T
Feel free to ask any specific questions you have about my demos -- I try to include useful comments but I know that sometimes comments aren't quite enough.