Custom Serial???
Laurent R
Posts: 27
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 ) from an existing object?
Thanks
Laurent
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 ) from an existing object?
Thanks
Laurent
Comments
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.
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
Regards
Laurent
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.
with an additional Parity bit. Also the Buffer size can easy be changed.
Andy
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 ?
Thanks
Laurent
What you need to do:
1.
Add some VARs, so that you can pass the additional parameters to the PASM
...
long bit_ticks
' new
long dt_size
long dt_parity
2.
modify the start function to accept additional parameters and set the variables accordingly
PUB start(rxpin, txpin, mode, dsize, dpar, baudrate) : okay
...
dt_size:=dsize
dt_parity:=dpar
3.
get the additional parameters in the pasm code
' find this
add t1,#4 'get bit_ticks
rdlong bitticks,t1
' new code
add t1,#4
rdlong datasize, t1
add t1,#4
rdlong parity, t1
4.
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
5.
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