Shop OBEX P1 Docs P2 Docs Learn Events
sending data to PC through serial port of Prostick USB — Parallax Forums

sending data to PC through serial port of Prostick USB

huynh153huynh153 Posts: 3
edited 2009-10-15 09:32 in Propeller 1
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,

Comments

Sign In or Register to comment.