intercommunications between 2 ProtoBoard with rs232 NO 2
nomad
Posts: 276
intercommunications between 2 ProtoBoard with rs232 NO 2
hi,
today i have testing:
1) in TestSlave_1.spin --> sender
ExtSerial.dec(sendByte) -> on TestMasterVga_1 = output == 0
with
ExtSerial.tx(sendByte) -> = output == 0
with
ExtSerial.str(string("A",10,13)) = output == 0
2) in TestMasterVGA_1.spin --> Receiver
if(c := ExtSerial.rxtime(500)) => 0
str := c
text.out($0D)
text.dec(str)
now i have more problems as yesterday, please help me.
i am looking for the correct code to send a
LONG send_longVal as 875 from the Slave to the Master
and
reiceive a LONG rec_longVal into the Master and the Master working with this value.
as code: TestSlave_1.spin
TestMasterVga_1.spin
@deSilva:
hi, i think you understand german. deutsches Forum,......
<< ich hab einige probleme mit der communication:
fuer deine gestrige antwort danke ich.
so, wie ich's versteh soll ich den gesendeten string mit dem Number-Object
in eine zahl convertieren.
da hab ich einen knopf in der leitung:
wenn ich (falls das ueberhaupt geht) vom Slave einen dezimalen wert z.b.
LONG send_longVal := 875
(mit Ext.Serial.dec(var) an den Master sende
empfaengt das master ja eine zahl z.b. 875, warum sollte ich diese zahl
wieder convertieren.
auch hab ich so meine probleme, deinen hinweis zu befolgen:
(Best you collect all characters (upto the stop condition, e.g. 13)
in a vector, add a zero byte.
and let NUMBERS.fromString(..) do the dirty work )
ich waere sehr dankbar, wenn ich hilfe bekaeme.
>>
regards
nomad
hi,
today i have testing:
1) in TestSlave_1.spin --> sender
ExtSerial.dec(sendByte) -> on TestMasterVga_1 = output == 0
with
ExtSerial.tx(sendByte) -> = output == 0
with
ExtSerial.str(string("A",10,13)) = output == 0
2) in TestMasterVGA_1.spin --> Receiver
if(c := ExtSerial.rxtime(500)) => 0
str := c
text.out($0D)
text.dec(str)
now i have more problems as yesterday, please help me.
i am looking for the correct code to send a
LONG send_longVal as 875 from the Slave to the Master
and
reiceive a LONG rec_longVal into the Master and the Master working with this value.
as code: TestSlave_1.spin
TestMasterVga_1.spin
@deSilva:
hi, i think you understand german. deutsches Forum,......
<< ich hab einige probleme mit der communication:
fuer deine gestrige antwort danke ich.
so, wie ich's versteh soll ich den gesendeten string mit dem Number-Object
in eine zahl convertieren.
da hab ich einen knopf in der leitung:
wenn ich (falls das ueberhaupt geht) vom Slave einen dezimalen wert z.b.
LONG send_longVal := 875
(mit Ext.Serial.dec(var) an den Master sende
empfaengt das master ja eine zahl z.b. 875, warum sollte ich diese zahl
wieder convertieren.
auch hab ich so meine probleme, deinen hinweis zu befolgen:
(Best you collect all characters (upto the stop condition, e.g. 13)
in a vector, add a zero byte.
and let NUMBERS.fromString(..) do the dirty work )
ich waere sehr dankbar, wenn ich hilfe bekaeme.
>>
regards
nomad
{****************************************************************************** TestMasterVga_1.spin ******************************************************************************} OBJ ExtSerial : "FullDuplexSerial" ' Full Duplex Serial Controller text : "vga_text" ' Create vgaText-object CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 serRecv = 1 ' Receive on I/O pin 0 = red serXmit = 0 ' Transmit on I/O pin 1 = black VAR BYTE str LONG rec_longVal PUB main | c text.start(16) text.str(string("Serial-InputTestMaster",13,10)) ExtSerial.start(serRecv,serXmit,%0000,9600) ' 9600 Baud repeat 'text.str(string("repeat",13,10)) if(c := ExtSerial.rxtime(500)) => 0 ' Wait up to 500ms for a character 'text.str(string(" Received",13,10)) str := c text.out($0D) text.dec(str) 'waitcnt(30_000_000 + cnt) case c "0".."9": ' do something with a digit "A".."Z","a".."z": ' do something with a letter '13: ' ok, here's a return ' 8: ' backspace key {*************************************************************************** TestSlave_1.spin ---------------- ***************************************************************************} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 serRecv = 0 ' Receive on I/O pin 0 serXmit = 1 ' Transmit on I/O pin 1 ledon = 4 VAR BYTE sendbyte OBJ ExtSerial : "FullDuplexSerial" Pub Test1 dira[noparse][[/noparse]ledon]~~ ExtSerial.start(serRecv,serXmit, 2, 9600) '0,1,2,9600 '- rxpin,txpin,mode,Baud ' -1 = receive = read (rxpin) ' 0 = transmission = write (txpin) ' - depends on your set up sendbyte := 125 repeat 5000 ' repeat 5 times !outa[noparse][[/noparse]ledon] 'ExtSerial.tx(sendbyte) ExtSerial.str(string("A",10,13)) ' \r = for linux carridge return 'waitcnt(100_000_000 + cnt) 'wait a length of time '----------------------------------------------------------------------------------
Comments
When you transfer numerical data via asynchronious protocols it has been good practice from times ago to send ASCII characters, i.e. %0011_001 = "1" rather than %0000_0001
This is somewhat redundant, as you could transfer twice the amount of data using "binary"; but you can check the datastream very easily by connecting a terminal (program).
This means the sender has to convert a binary number (e.g. a LONG) into single characters before transmitting it, similar as when displaying them to TV.
FullDuplexSerial (FD) has - according to some convention most driver writers follow - a nice routine DEC that will do this:
FD.DEC(123_567_789)
The receiver has to "assemble" that again, alas there is no routine for this in the FD object. But there is something in NUMBERS!
So what the slave has to do is:
But it may be the number you are expecting has a more complex format (maybe it's a floating point number). In that case you would only strore the single characters in a string and let someone else "decode" it.
Post Edited (deSilva) : 9/30/2007 12:42:14 PM GMT
thanks for your answer,
wusch, i hope that i understand you and your code.
it this code correct (excuse me) now i am online:
thank you for your help
(on german, bin froh um deine hilfe, und wuerde mich ueber eine antwort freuen )
regards
nomad
You have to SEPERATE the sent numbers by some non-digit, e.g. a blank or a carriage return...
hi deSilva,
thanks, somethings goes wrong
in the meantime i have testing the 2 progs.
on slave_1:
if i make: fdSerial.dec(875) ' your tip
then on master with
REPEAT
c := ExtSerial.rx-"0" ' wrong: c := rx-"0"
'IF c<0 OR c>9 ' dont run = no output
' QUIT
values := 10*values +c ' if value = byte then output = 176
text.out($0D) '
text.dec(values) ' output: values as byte =176 if values as long -143165760
'text.dec(c) ' dec(c) = -48 , bin(c,8) = 11010000 , hex(c,8) = FFFFFFD0
the output on master: 176
but i know nothing whats going wrong.
in your last answer you write:
<< Not quite....
You have to SEPERATE the sent numbers by some non-digit, e.g. a blank or a carriage return...
>>
in which prog?,
but i think, please, i posting now the lastest programms:
please corrected my programm.
on german:
<< da ich im augenblick einen knopf in der leitung habe.
bitte korrigiere meine beiden programme.
schande ueber mein haupt. aber ich hab aus meiner sicht alles probiert,
ich bin schon froh wenn jetzt beim master ein output kommt.
>>
thanks for your help
now the pgm:
i think i come back tomorrow.
nomad
I gave you some code snippets YOU have to put into your own right context! It is no use to put them SOMEWHERE into your program...
(a) The receiver must be put into a position to KNOW that there will be a number NOW and that this number string has now ended. So
- either it must learn about the timingcontraints you use in the transmitter (WAITCNT(10000000))
- or you send "separators" e.g. 13 as I suggested in my snippet!
(b) So please do what suits you best.E.G.
Transmitter:
Receiver:
And by all means use a LONG for value (and for c as well)
And think about why this snippet is just the same as the the two others I gave you
Post Edited (deSilva) : 10/1/2007 8:08:08 AM GMT
excuse my stupid questions.
thanks for your help
regards
nomad