View Full Version : Custom Serial???
04-06-2009, 04:09 PM
For a project I need to be able to change the data format of the communication...
I mean 5 to 8 data bits, parity bit or not, simple or double stop bit...
Is this already done?
Is it possible to do it quite easily (for a noob like me http://forums.parallax.com/images/smilies/tongue.gif ) from an existing object?
04-06-2009, 05:04 PM
Do you need full duplex? At which speed do you want to receive/send? Can the speed of the 'channels' be different? Is one channel fixed to standard serial settings? (1 start, 8 data, 1 stop) Or have both channels to be configurable? What should happen with the bits when you reduce from 8 bit to 5? Cut the upper bits? Cut the lower? Or do you still want to transfer the whole byte packaged in two 5 bit transfers?
Changes in the 'Simple Serial' would be easy, but it does not support duplex and it is only low speed.
The 'Full Duplex Serial' is not so easy to adapt for a noob!
Depending of the answer to my questions the complexity of the implementation ranges from very easy to difficult. E.G. in case of different baudrates of the channels you have to buffer the stuff and hardware flow-control would be needed to indicate the faster connection that the buffer is full.
04-06-2009, 05:38 PM
Thanks for the quick answer
1) I don't need full duplex
2) from 2400 to 115200 bauds (default 9600)
3) I need just 1 channel but i have be able configure it by soft and store configuration in a EEPROM
4) After discuss, it seems useless to send 5 or 6 data bits so be able to use 7 (true ascii) or 8 data(standard) will be great and enough
04-06-2009, 06:16 PM
Ah .. now I got it. I understood that you have an incoming serial data stream on one line in format A and you want to send it out on another interface with fromat B. But you only need·a driver with configurable format.
Then I'd take the 'Simple Serial' which is written in SPIN and adapt that. As first step I'd add the extra logic you need for number of stopbits and parity and so on.
Once it works you can convert it to PASM to speed it up.
You have to add some code which reads a command buffer to see if the application want's to send or receive and of course the data to be send. According to the command it branches into the send or receive code, which is the PASM translation of the two methods in 'Simple Serial'.
Reading parameters from a buffer is simple. You can have a look at my first post of thread http://forums.parallax.com/forums/default.aspx?f=25&m=338494 to see how it works.
Hope that helps.
04-07-2009, 02:29 AM
Here is a variation of the FullDuplexSerial object, which allows configuration of the datasize 7..9 bits,
with an additional Parity bit. Also the Buffer size can easy be changed.
04-07-2009, 03:01 PM
Great Ariba ...
But as I'm new to the propeller in spin, I'm also in asm...
In that code, there is a constant to set the numbers of databits ... Is it possible to replace this constant by a parameter?
So I can set the number of databits when I call the start method ?
04-07-2009, 05:01 PM
Some changes here, some changes there and you can. I wonder why the author did not do it with parameters but with constants.
What you need to do:
Add some VARs, so that you can pass the additional parameters to the PASM
modify the start function to accept additional parameters and set the variables accordingly
PUB start(rxpin, txpin, mode, dsize, dpar, baudrate) : okay
get the additional parameters in the pasm code
' find this
add t1,#4 'get bit_ticks
' new code
rdlong datasize, t1
rdlong parity, t1
now you have to determine some additional variables in the dat section because in some cases parity and datasize are used differently. For this you have to add some longs at the end of the code but before the RES.
' straight after the code given in 3.
shl stopbit, datasize ' stopbit is no longer a constant, so create it
add datasize_p1, datasize
add datasize_p3, datasize
sub datasize_m31, datasize
shl datamsk, datasize
sub datamsk, #1
' at the end where you find the stopbit long change that line
stopbit long 1
' and add these
datamsk long 1
datamsk_mux long 0
datasize_p1 long 1
datasize_p3 long 3
datasize_m31 long 31
now search for #DATASIZE+1 and replace it with datasize_p1
search for #DATASIZE+3 and replace it with datasize_p3
search for #31-DATASIZE and replace it with datasize_m31
search for #DATAMSK and replace it with datamsk
search for #DATAMSK+1>>1 and replace it with datamsk_mux
search for #PARITY and replace it with parity
Sorry that I currently can not come with tested code, but I don't have the propeller at hand.
Of course you can not change the settings after start. Would be possible as well, but maybe not worth the efford. Simply stop the serial and restart it if the settings change during runtime.
Post Edited (MagIO2) : 4/7/2009 10:07:05 AM GMT