Serial Communication - Input from Pin
herold
Posts: 66
I like to get the state from an input pin (high/low) checked as often as possible and transfer the data (0/1) via serial to the PC.
Is there any basic source code available for this?
Is there any basic source code available for this?
Comments
At 115200 baud that would be about 11,520 times a second.
The code would be very simple:
DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX
FREQ 50_000_000
InPin VAR RB.0 ' Change this to whatever pin you want to monitor
SOutPin VAR RB.1 ' Change this to whatever pin you want serial output from
Temp VAR BYTE
PROGRAM Start
Start:
· INPUT InPin
Again:
· Temp=InPin
· SEROUT SOutPin, N115200, Temp
GOTO Again
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"What's the difference between ignorance and apathy ?"
"I don't know, and I don't care."
Post Edited (Bean (Hitt Consulting)) : 7/6/2005 5:50:56 AM GMT
DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX
FREQ 50_000_000
InPort VAR RC ' Make this to either RB or RC
SOutPin VAR RB.1 ' Change this to whatever pin you want serial output from
PROGRAM Start
Start:
· SEROUT SOutPin, N115200, InPort
GOTO Start
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"What's the difference between ignorance and apathy ?"
"I don't know, and I don't care."
·
Thank you very much for your support.
But I believe that at 115,200 bits per second, the byte transmission rate is 11,520 bytes per second. Remember, the are 10 bit times per byte.
So at one sample per transmission, the input would be sampled and transmitted 11,520 times per second.
Can a PC reliably keep up with that on a continuous streaming basis? I not certain, but I would not bet on that. Probably depends on the number of buffers in the PC's UART, and whatever else WINDOZE is doing.
If the user indeed needs (only) the absolute fastest transmission out of an SX, that can be reliably accomplished continuously at 5 megabits per second, and in bursts at 10 megabits per second. That however is well beyond most (all?) PC's ability to keep up.
Cheers,
Peter (pjv)
Post Edited (Paul Baker) : 7/6/2005 3:32:10 PM GMT
I bought the USB-Serial adapter your company is featuring. Does it matter which pin I use for the output in order to receive data in the PC?
If I send data the USB-serial device should be blinking (red/green leds) th same way when I do program it, right? I assume the output data is send trough the SK Key?
Post Edited (herold) : 7/8/2005 7:02:41 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
Thank you for the reply. Can I use the USB2SER module you offer:
http://www.parallax.com/detail.asp?product_id=28024
If not, is there any hardware available that I can buy to hook the SX board up to my PC via Serila or USB? When I ordered the kit I was under the impression I can do this with the kit.
Thank you
Thomas Herold
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Is it the same driver that comes with the serial to USB adapter? I bought this adapter with the SX board.
http://www.parallax.com/detail.asp?product_id=800-00030
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I got my USB2Ser device today:
http://www.parallax.com/detail.asp?product_id=28024
and plugged it onto the SX board. But I can't get data out of it!
In the documentation to the USB2SER it says that the red and green LED's for TX & RX activity light up.
I use this simple basic program:
DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX
FREQ 50_000_000
InPin VAR RB.0 ' Change this to whatever pin you want to monitor
SOutPin VAR RB.1 ' Change this to whatever pin you want serial output from
Temp VAR BYTE
PROGRAM Start
Start:
INPUT InPin
Again:
Temp=InPin
SEROUT SOutPin, N115200, Temp
GOTO Again
2) All pins are made inputs unless you use NOSTARTUP -- you don't need to make "InPin" an input.
3) You have no pacing between bytes and are sending them at a pretty fair clip; could this be part of the problem.
4) You're sending zeros and ones -- can your PC program deal with this?
Update:
I wrote a simple demo that works -- but I had to put a pacing delay between bytes.· The output of the SX (RA.1 in my demo) is connected to the RX pin on the USB2SER adapter.· I used Hyperterminal setup at 115200 baud with no flow control.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 7/14/2005 4:07:39 AM GMT
Thanks a lot. I installed the driver again and was running your test program. The debugger shows the signal coming out on the programmed pin.
Here is what I do:
- I unplug the FTDI US232B USB to Serial Adapter which I used to program the chip
- I plugin the USB2SER chip directly into the SX board (4pin connection)
- I plugin the other side into the USB on my PC
No blinking on the USB2SER, no data comes out. I also checked with Hyper terminal. Any ideas where to look?
If the connection this way is not ok, how exactly do I need to make a connection from the SX board to the 4pin USB2SER adapter?
Post Edited (herold) : 7/14/2005 6:59:28 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I understand, is there anyway to test the USB2SER to find out if it is still working?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
The USB2SER does not show any LED's blinking and Hyperterminal is not showing anything as well. Meaning I damaged it?
As soon as I connect the RX pin and the VSS the USB2SER should start blinking, right?
I used the attached program to suss everything out.· Run the program with these connections to your USB2SER:
RA.0
TX
RA.1
RX
·Vss·
Vss
The program starts with a loop that just receives.· Fire up Hyperterminal, select the comm port assigned to your USB2SER, then open the connection -- you should have to press a key 10 times (the red LED will light with each keypress).· After that, when you press a key the SX will echo it back with a little ">> " prefix -- the green LED will light when this happens.· Note that at 115200 the LEDs are on nearly simultaneously.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thank you so much for your support...
I get 2 errors running your program:
Line 71: Error 5, Pass 1: Byte Parameter expected RXBYTE
Line 75: Error 5, Pass 1: Byte Parameter expected RXBYTE
I am running version SX-Key version 3.1.
Again, thanks so much for all the help. After updating the compiler your Serin Serout Test program runs!
The other sample programn 'High Speed Serout' still doesn't work. At least I know the USB2SER adapter is working and I may need to experiment with baud rates. Probably the communication is very sensitive at high speed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I got it finally all going, thank you for your help and support. But guess what I have the same speed problem than I had with the fastest Stamp chip.
I cannot get more than 2k into my PC, which is reaaly slow. With 115200 baud I should get at least 10k in speed.
Also if I don't include a PAUSE 1 statement the transmission seems to be screwed up.
I am running a compiled Realbasic aplication which reads the serial port at max speed.
Where is the bottleneck? Do I have to program the SX chip in assembler to get more speed out?
Post Edited (herold) : 7/15/2005 5:17:46 AM GMT
Please post the program you are using.
If the "PAUSE 1" is inside the loop that will really slow down the speed, you could try "PAUSEUS 100" which is only 0.1ms.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
Part of the problem you're going to have is overrunning the PC buffer -- can your PC/program handle that much data?· What I found was without the delay in the loop, characters were getting corrupted.· You might use Bean's suggestion an change the PAUSE 1 to PAUSEUS 100.
You're getting all the speed you can out of the SX -- the SX/B program is compiled to very clean assembly code.· What you may need is a special-purpose serial card on your PC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
With this settings I get about 5kb in data per second, but the transmission is no more correct. But 5K is not even considered highspeed. I switched from the Basic Stamp BSX2e to this SX board as I though I get more speed out of it, but in terms of serial communiation it is not more.
With a PAUSEUS 100 I get max 2kb in data, which I find is really slow. With a baud rate of 115200 how many bytes per second is possible?
I cannot believe that my USB port cannot handle more than 2k per second as Jon stated. I am using the USB2SER interface, which can handle·up to 3MBit.
Post Edited (herold) : 7/15/2005 6:02:16 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax