1-wire or rs232?
Hi all,
I would like to hear some thoughts about the following setup:
I have a stamp that is connected via pins 12 (TX_pin) and 13 (RX_pin)
to a sx18. The sx18 provides 3 serial TX/RX ports and a multimaster i2c bus.
The sx18 never sends data to the stamp unless told to do so by the stamp.
All datatransfers are initiated by the stamp sending a command.
Commands are something like: 'read data from port1' or 'send data to port3'
etc.
My first approach (not tried it yet) is to use serin and serout with
handshake like this:
To write data: serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]command]
serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]outputdata]
To read data: serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]command]
serin RX_pin\TX_pin,buad,timeout,label,[noparse][[/noparse]inputdata]
Problem with writing data is that the exact number of databytes written
is not known at forehand because the result of the formatters depends on
the actual datavalues, so how does the sx18 know it has received a new
command
and not just a databyte? My solution is to use a timeout value between the
last
databyte sent and a new command that is at least twice the pace value.
Problem with reading data is that I use the timeout value of serin to
determine
there is no more data to read. How much bytes are actually read? This I
solved
by letting the sx18 always send the number of available bytes first. However
this
only works when reading the data into a single string variable.
I think the above approach should work.
My second approach (also not tried yet, don't have a bs2p) is to use 1-wire,
i.e stamp pin 12 is 1-wire and pin 13 is used as a rs232 output or handshake
that I use
to send commands to the sx18 or to let it know the stamp is busy.
To write data: serout 13,baud,pace,[noparse][[/noparse]command] or low 13 (high 13 means busy)
owout 12,mode,[noparse][[/noparse]outputdata]
To read data: serout 13,baud,pace,[noparse][[/noparse]command] or low 13 (high 13 means busy)
owin 12,mode,[noparse][[/noparse]inputdata]
This way I have a dedicated command connection or handshake and a dedicated
dataconnection.
The memory function of 1-wire should allow me to send the command before
reading or writing
data, I think. Now the sx18 can simply detect when writing data ends because
the owout
command ends. For owin I use the same approach as for serin: let the sx18
first send
the number of bytes available. I assume the owin command will timeout when
no data is
received.
I would like to know if anyone has ever done such a setup before and how
they solved the inputdatalist problem (if possible), because I would like to
use
the inputdata formatters rather than a single string variable and do the
decoding
myself. Also like to know which approach is preferable. There may be issues
I didn't
think of.
Regards peter
I would like to hear some thoughts about the following setup:
I have a stamp that is connected via pins 12 (TX_pin) and 13 (RX_pin)
to a sx18. The sx18 provides 3 serial TX/RX ports and a multimaster i2c bus.
The sx18 never sends data to the stamp unless told to do so by the stamp.
All datatransfers are initiated by the stamp sending a command.
Commands are something like: 'read data from port1' or 'send data to port3'
etc.
My first approach (not tried it yet) is to use serin and serout with
handshake like this:
To write data: serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]command]
serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]outputdata]
To read data: serout TX_pin\RX_pin,baud,pace,[noparse][[/noparse]command]
serin RX_pin\TX_pin,buad,timeout,label,[noparse][[/noparse]inputdata]
Problem with writing data is that the exact number of databytes written
is not known at forehand because the result of the formatters depends on
the actual datavalues, so how does the sx18 know it has received a new
command
and not just a databyte? My solution is to use a timeout value between the
last
databyte sent and a new command that is at least twice the pace value.
Problem with reading data is that I use the timeout value of serin to
determine
there is no more data to read. How much bytes are actually read? This I
solved
by letting the sx18 always send the number of available bytes first. However
this
only works when reading the data into a single string variable.
I think the above approach should work.
My second approach (also not tried yet, don't have a bs2p) is to use 1-wire,
i.e stamp pin 12 is 1-wire and pin 13 is used as a rs232 output or handshake
that I use
to send commands to the sx18 or to let it know the stamp is busy.
To write data: serout 13,baud,pace,[noparse][[/noparse]command] or low 13 (high 13 means busy)
owout 12,mode,[noparse][[/noparse]outputdata]
To read data: serout 13,baud,pace,[noparse][[/noparse]command] or low 13 (high 13 means busy)
owin 12,mode,[noparse][[/noparse]inputdata]
This way I have a dedicated command connection or handshake and a dedicated
dataconnection.
The memory function of 1-wire should allow me to send the command before
reading or writing
data, I think. Now the sx18 can simply detect when writing data ends because
the owout
command ends. For owin I use the same approach as for serin: let the sx18
first send
the number of bytes available. I assume the owin command will timeout when
no data is
received.
I would like to know if anyone has ever done such a setup before and how
they solved the inputdatalist problem (if possible), because I would like to
use
the inputdata formatters rather than a single string variable and do the
decoding
myself. Also like to know which approach is preferable. There may be issues
I didn't
think of.
Regards peter