PDA

View Full Version : Serial port buffering



Tom P
05-04-2008, 11:42 PM
HELPPP
I want to be able to use a propeller to receive新erial data from an RF receiver and then resend a buffered serial stream out another port.
Has someone already done this? Can新omeone戢ssist with some搾ode?
thanks in advance
Tom

Mike G
05-05-2008, 12:54 AM
Sure Tom you can use the fullDuplexSerial object found in the object exchange.

OBJ uart : "FullDuplex"

PUB Start

uart.Start(31, 30, 2400)

'Wait for serial input
repeat
GetSerialCommand

tpw_man
05-05-2008, 01:38 AM
Do you mean buffer a command, and then transmit it out all at once? If you just are using the propeller as a redirection device, here is the code. It assumes you are using a 5 MHz crystal. Using the buffered driver(FullDuplexSerial), you have to use an external clock source.





CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

obj
ser : "FullDuplexSerial"

pub main
ser.start(<input pin>, <output pin>, <mode(usually 0)>, <baud rate>)
repeat
ser.tx(ser.rx)





That will retransmit the serial stream as fast as possible with the same baud rate as input and output. If you want different baud rates:




CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

obj
ser1 : "FullDuplexSerial"
ser2 : "FullDuplexSerial"

pub main
ser1.start(<input pin>, <irrelevant>, <mode(usually 0)>, <baud rate>)
ser2.start(<irrelevant>, <output pin>, <mode(usually 0)>, <baud rate>)
repeat
ser2.tx(ser1.rx)





The object ser2 transmits the data, and the object ser1 receives the data. This should do what you want. Change <input pin>, <output pin>, perhaps <mode>, and <baud rate> to your required data. With the FullDuplexSerial object there is no odd baud rate calculations as on the BS2. FullDuplexSerial has 16 byte internal buffers to prevent losing received data or having to wait to send data. If the baud rates are different, you might have problems transmitting packets as fast as they are received and vice-versa. The buffer sizes are changeable, but it requires a little work.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!

Tom P
05-05-2008, 03:40 AM
Thanks To:TPW_man

I'am a bit confused? concerning the two sample codes shown - and to which one should be actaully used?
- Iam pretty new to the propeller,so bare with me here!

Bascially I want a real-time or near real time serial re-sending sceme. As data comes in its immediately re-sent but with buffering if needed, typically 2400baud
The incoming serial data could be displyed for debugging if possible (DEBUG) and get immediately re-sent out another port as a serial stream at the same speed.
I have a Propeller Demo board, could that be used for this project?
thanks in advance
Tom

tpw_man
05-05-2008, 04:32 AM
You can use the bottom example for your purposes. It will do what you have described except DEBUG data as it comes in. The Demo Board could be used. Code for making a debugging version:





CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

obj
ser1 : "FullDuplexSerial"
ser2 : "FullDuplexSerial"

pub main | char
ser1.start(<input pin>, <output pin>, <mode(usually 0)>, <baud rate>)
ser2.start(31, 30, 0, 9600)
repeat
char := ser1.rx
ser1.tx(char)
ser2.tx(char)





This example will send whatever is received out to the programming pins(31, 30) at 9600 baud so you can view it on the computer, and send the same data out to another pin at the input baud rate.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!

StefanL38
05-05-2008, 04:48 AM
hello,

as the comments under the code-sample says

sample 1: same baudrate

sample 2: different baudrates


There are still some questions to clear:

What is the MAIN-purpose of this project ?
serial datastream debugging ?
or something else ?

If it is something else tell it to us. Maybe there is a completed different solution to the MAIN-purpose !

Are BOTH devices sending AND receiving data ?
(this would be a reason to use sample-code 2)

Does one or both of the devices use hardware-handshaking or software-handshaking that makes it nescessary to buffer the datastream?
If so - how many bytes have to be buffered ?

What voltage-levels do you need ?
Standard-RS232-devices are using +-12V

The Demoboard has ONE USB-to-serial-converter "onboard"
If the second port is a standard serial device you will need a voltageshifter 0/3,3V to -12V/+12V

What do you mean by (DEBUG)?

Debug-command as on a basic stamp meaning send a string to a serial port ?
Should this be a THIRD serial port ?

Displaying the incoming characters on a TV?, on a VGA ?

If you want to display the incoming or outgoing serial datastream you could do this
by using a Y-cable. Y-cable means the interested PIN Rx or Tx has a SECOND cable soldered
to the Rx/ Tx-Pin and the other end of this cable is connected to a third D-SUB9-Plug that
could be connected to a serial port of a PC to view the serial data.

best regards

Stefan

Tom P
05-05-2008, 11:54 PM
I want to try TPW_man's code above with the debugs line above.
I want to experiment using the PRopeller Demo board
I understand I will have to substitute the pin numbers and baud rate.
In the program where its want <input pin> for example -- do I just insert 0 or P0 for the input/output pin?
--Also for baud rate what do I enter for say 2400 baud?

tpw_man
05-06-2008, 12:51 AM
You can experiment with the demo board just fine. For the pins, you just put in the pin number. "0" sets pin 0. There is no fancy calculations required for FullDuplexSerial like there is with SERIN/SEROUT. Just put in "2400" for 2400 baud.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!

Tom P
05-06-2008, 02:16 AM
tpw_man

I entered the code in the propeller program and fired the demo board up.
I substituted the input numbers 0 for input and 2 for output, entered 2400 to start and tried to compile the program.
I get an error message [expected an expression term] and the word MODE was highlighted.
I did not change <mode <(usually 0).
What is this MODE command?
Tom

Tom P
05-06-2008, 02:26 AM
TPW_man
Sorry for all the questions!!
I figured out that the just needed to enter (0) for the mode after the baud rate, in your program example.
The I compiled the program and it got a bit further, but I got an error [variable needs operator]
with (char) was highlighted.
what do I need to do at thia point?
I think I'am almost there now!
thanks
Tom

Mike Green
05-06-2008, 02:26 AM
You left out the mode parameter (see previous examples). There are 4 parameters to the FullDuplexSerial start method, the receive pin, transmit pin, mode, and Baud.

For the other error message, you'll need to give a little context (like the line where the message refers).

Tom P
05-06-2008, 02:53 AM
I figured out that the full duplex needs RX,TX,mode and baud.
I tried to recompile the program again but found another problem.
Now I get [variable needs operator] and the (char) under the repeat command in the debug version of the program gets highlighted!!
Getting closer
but no cigar!
tom

tpw_man
05-06-2008, 05:11 AM
That's very odd. Are you sure you didn't leave out the colon? It compiles when I copy and paste what I posted into the propeller tool.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!

Tom P
05-06-2008, 07:52 PM
TPW_man
Ops- I finally got ithe program to compile- there was no space between the char and the colon!

I have my receiver connected to the serial input (0)of the Propeller and an LCD connected to the serial output (2).
I get a lot of gibberish when I connect a serial LCD for test to the serial output at pin 2.

When I experimented with the STAMP 2 - I used -- SERIN 7, 16780, [WAIT ("*"), cnt ]
How can use an equivalent with the input on the propeller?

Also - how does debug work with the propeller? I did not see a debug screen or characters on the PC screen.
thanks in advance
Tom

--------------------------------------------------------------------------------------------------
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
ser1 : "FullDuplexSerial"
ser2 : "FullDuplexSerial"
pub main | char
ser1.start (0,2,0, 2400)
ser2.start (31,30,0, 2400)
repeat
char := ser1.rx
ser1.tx(char)
ser2.tx(char)

StefanL38
05-06-2008, 08:33 PM
Hello Tom,

Ok you seem to be a guy that is aksing question very quickly
(i myself prefer to ask a SLOW questions combined with serving DETAILED information ALL AROUND my question)

You seem to like the ping-pong game of just quick asking getting a SMALL answer
and then asking quickly again

OK let's play ping-pong - i got a quick question too:

what baudrate has your LCD ?

i guess this way it will take about 20 SMALL questions and again 20 answers until your problem is solved
but i start enjoying this game http://forums.parallax.com/images/smilies/lol.gif

so just "pong" back http://forums.parallax.com/images/smilies/turn.gif http://forums.parallax.com/images/smilies/roll.gif http://forums.parallax.com/images/smilies/hop.gif

Tom P
05-06-2008, 08:57 PM
I'am not a programmer, but a hardware person, so programming is more difficult for me, so the learning curve is a bit slow.
I'am a somewhat more familiar with the STAMP 2 but new to the propeller.
The LCD is set for 2400 baud, and I am trying to use the LCD to monitor the output of the serial port 2 on the Propeller.
I'am sending data from a STAMP2 collecting data from a number of TSL-230 sensors. The STAMP 2 is sending the data via radio to a receiver which is now connected to the propeller but was oringally connected to a second STAMP 2. SInce the STAMP 2 could not buffer the incomming serial data and retransmitt it I needed to try a different solution. I want to use the output of the serial port 2 on the propeller to send a serial signal to an serial internet device.

StefanL38
05-07-2008, 04:49 AM
Hello Tom,

good posting !

i think now i have an overview about your project. You said on the LCD you get "gibberish"

There are different possabilities from where the error comes. Now you have to chase for the error
by excluding.

The principle is: reduce the number of components in the system and check the rest if it is working
properly. For checking use components with wich you are 100% sure that the checking component
is working properly

example: use serial port of a PC with hyperterminal instead of original device


reducing variety of the data:

make a small program for the propeller that will send ONE particular string like "123" every two seconds
connect the display directly to the propeller running this testprogram
does the display show correct data ?

maybe you have to change the mode-parameter
the modes are described in FullDuplexSerial.Spin in the PUB Start


make a small program for the basicstamp that will send ONE particular string like "123" every two seconds

connect the propeller directly (without radio-transmission in between) to the BS2 that sends out the data.
connect PC instead of LCD


test is the radio transmission Ok ?

precheck: BS2 sending out "123" connect BS2 directly to a PC serial port running hyperterminal
if receiving is OK install radio-transmitting in between:

BS2--->radio-tx---->radio-rx--->PC is the receiving still OK ?

then connect the display instead of the PC
BS2--->radio-tx---->radio-rx--->display

etc.

best regards

Stefan