sending data to PC through serial port of Prostick USB
huynh153
Posts: 3
Dear all,
I write a code to send data from Prostick USB to PC through the pin 31, 30, the code as:
{{ CODE}}
VAR
long sin, sout, inverted, bitTime, rxOkay, txOkay
byte data
PUB main
init(31, 30, 19200)
data := 3
repeat 100
tx(data)
PUB init(rxPin, txPin, baud): Okay
finalize ' clean-up if restart
rxOkay := rxPin > -1 ' receiving?
txOkay := txPin > -1 ' transmitting?
sin := rxPin & $1F ' set rx pin
sout := txPin & $1F ' set tx pin
inverted := baud < 0 ' set inverted flag
bitTime := clkfreq / ||baud ' calculate serial bit time
return rxOkay | TxOkay
PUB finalize
{{Call this method after final use of object to release transmit pin.}}
if txOkay ' if tx enabled
dira[noparse][[/noparse]sout]~ ' float tx pin
rxOkay := txOkay := false
PUB tx(txByte) | t
{{ Transmit a byte; blocks caller until byte transmitted. }}
if txOkay
outa[noparse][[/noparse]sout] := !inverted ' set idle state
dira[noparse][[/noparse]sout]~~ ' make tx pin an output
txByte := ((txByte | $100) << 2) ^ inverted ' add stop bit, set mode
t := cnt ' sync
repeat 10 ' start + eight data bits + stop
waitcnt(t += bitTime) ' wait bit time
outa[noparse][[/noparse]sout] := (txByte >>= 1) & 1 ' output bit (true mode)
if sout == sin
dira[noparse][[/noparse]sout]~
{{END}}
After i load the code into the RAM of Prostick USB, i use the HyperTerminal to view the result by connecting the usb with Hyperterminal with the baudrate of 19200, but I could not receive any data. Could anyone please show me how could i modify the code so that I can recieve the data (number of 3 in this code) in the Terminal program.
Thanks,
Pthien,
I write a code to send data from Prostick USB to PC through the pin 31, 30, the code as:
{{ CODE}}
VAR
long sin, sout, inverted, bitTime, rxOkay, txOkay
byte data
PUB main
init(31, 30, 19200)
data := 3
repeat 100
tx(data)
PUB init(rxPin, txPin, baud): Okay
finalize ' clean-up if restart
rxOkay := rxPin > -1 ' receiving?
txOkay := txPin > -1 ' transmitting?
sin := rxPin & $1F ' set rx pin
sout := txPin & $1F ' set tx pin
inverted := baud < 0 ' set inverted flag
bitTime := clkfreq / ||baud ' calculate serial bit time
return rxOkay | TxOkay
PUB finalize
{{Call this method after final use of object to release transmit pin.}}
if txOkay ' if tx enabled
dira[noparse][[/noparse]sout]~ ' float tx pin
rxOkay := txOkay := false
PUB tx(txByte) | t
{{ Transmit a byte; blocks caller until byte transmitted. }}
if txOkay
outa[noparse][[/noparse]sout] := !inverted ' set idle state
dira[noparse][[/noparse]sout]~~ ' make tx pin an output
txByte := ((txByte | $100) << 2) ^ inverted ' add stop bit, set mode
t := cnt ' sync
repeat 10 ' start + eight data bits + stop
waitcnt(t += bitTime) ' wait bit time
outa[noparse][[/noparse]sout] := (txByte >>= 1) & 1 ' output bit (true mode)
if sout == sin
dira[noparse][[/noparse]sout]~
{{END}}
After i load the code into the RAM of Prostick USB, i use the HyperTerminal to view the result by connecting the usb with Hyperterminal with the baudrate of 19200, but I could not receive any data. Could anyone please show me how could i modify the code so that I can recieve the data (number of 3 in this code) in the Terminal program.
Thanks,
Pthien,
Comments
Do you write your own serial driver for learning? I ask because there are well tested drivers in the Object Exchange and there is no other reason to write a serial driver by your own than education.
My expectation is that SPIN is to slow for 19k Bit. You could attach an LED to the tx-pin and see what happens. If you miss the right point in time to start the waitcnt, waitcnt will wait for ~50seconds.
I'd start with a lower baud-rate. If your driver works then you can optimize it for speed and see how fast you can get.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade, RetroBlade,·TwinBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm