Shop OBEX P1 Docs P2 Docs Learn Events
serin serout problem, please help — Parallax Forums

serin serout problem, please help

4ish4ish Posts: 24
edited 2005-08-05 23:10 in Learn with BlocklyProp
hey everyone...

I'm trying to do something for a class but I'm not getting anywhere, I was hoping someone could give me some pointers...

basically I have two BS2 and I want to establish communication between them... the first one (TX) is hooked up to a transmitter, and the second (RX) is obviously hooked up to a receiver, both parallax products..

now what I want is to basically transmit a string say "will this work?" and receive it on the other end... from my understanding, since they are on two different STAMPS I cannot use the flow control for confirmation...

so I have
LoopThis:
SEROUT TxPin, BaudR, [noparse][[/noparse]"send this sentence"] 
GOTO LoopThis




running on the TX stamp and

Loop2:
SERIN RxPin, BaudR, [noparse][[/noparse]variable]
DEBUG variable
GOTO Loop2




on the RX stamp...

but the problem is I recieve a lot of undesired characters as well, as though it was a parity issue or something, I really dont know... but it doesnt give me the string... I'm using 2400 as my baudrate

does anyone know how to solve this problem? perhaps by using a byte array, some other sort of synchronization etc... any help would be much appreciated... thank you

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-03 09:01
    The problem you've created is that you're interrupting your ability to receive characters with DEBUG -- DEBUG takes time (it's actually serial output at 9600 baud). What you can do is add pacing to your SEROUT (see the manual or help file) that will give the receiver time to DEBUG the character it just received.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-03 17:42
    Also, your "variable" on recieve should be recieving a string, not a data value.
  • 4ish4ish Posts: 24
    edited 2005-08-03 18:35
    thank you guys for replying ...

    here's what I did to modify my code...
    'transmitter
    LOOP2:
    SEROUT txpin, ANTBaud, [noparse][[/noparse]"%*this is the cake"]
    
    GOTO LOOP2
    



    and

    'reciever
    variable2 VAR Byte(17)
    variable2(17) = 0
    
    
    SERIN rxpin, ANTBaud,[noparse][[/noparse]WAIT ("%*"), STR variable2\16\"0"]
    SEROUT lcdPin, ANTBaud, [noparse][[/noparse]STR variable2]
    
    



    basically I removed the debug and the loop on the reciever end and replaced by the WAIT and I'm now outputting into the LCD

    now this seems to work fine, so unless you guys can find any faults in it, then its good...

    now my other question is this... I dont know how long the sentence being sent is going to be, so how can I modify my receiver code to accept any N-size sentence? (right now the array is set to 17)


    thanks again
  • 4ish4ish Posts: 24
    edited 2005-08-03 18:55
    and one more thing... how can i put a string inside a variable?

    so that my code could become like this

    
    toSend VAR Byte (25)
    toSend = "this is the sentence"
    
    LOOP2:
    SEROUT txpin, ANTBaud, [noparse][[/noparse]"%*",toSend]
    GOTO LOOP2
    
    
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-03 21:21
    You can't -- PBASIC does not support strings directly. You can use an array of bytes, but that will use up your memory quite quickly. Since you're going Stamp-to-Stamp, let me suggest again that you put some pacing on your transmitter side so that the receiver has time to deal with each character that comes in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-04 18:40
    You CAN store your string in 'DATA' eeprom space:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    String1 DATA "Hello There",0
    StringLoc VAR Word· ' 1..2000
    MyByte··· VAR Byte
    I9600·· CON 16468 '16384 + 84
    MAIN:
    · SEROUT 16, I9600, [noparse][[/noparse]String1,13]· ' BAD!· Only sends first byte of 'String1'
    · '****** Below is what you want... *****
    · StringLoc = String1
    · GOSUB SendString
    · PAUSE 200
    · GOTO MAIN

    SendString:
    · READ StringLoc, MyByte
    · DO WHILE MyByte <> 0
    ··· SEROUT 16, I9600, [noparse][[/noparse]MyByte]
    ··· StringLoc = StringLoc + 1
    ··· GOTO SendString
    · LOOP
    · RETURN
    ·
  • 4ish4ish Posts: 24
    edited 2005-08-05 21:39
    thanks again for replying...

    allan, I tried your way, and it works... however I've decided to give each byte from the keyboard itself... so it just transmits what I type, letter for letter...

    so here's my current code...

    'tX
    PINNO CON 5
    ANTBaud CON 396
    LCDBaud CON 84
    TxPin CON 6
    toSend VAR Byte
    PAUSE 100
    
    LOOP2:
    DEBUGIN toSend
    SEROUT PINNO ,LCDBaud, [noparse][[/noparse]toSend]
    SEROUT TxPin ,ANTBaud,[noparse][[/noparse]"*",toSend]
    GOTO LOOP2
    
    END
    
    



    and
    'rX
    PINNO CON 5
    ANTBaud CON 396
    rxpin CON 0
    PAUSE 100
    
    variable2 VAR Byte
    
    LOOP2:
    SERIN PINNO, ANTBaud,[noparse][[/noparse]WAIT ("*"), STR variable2\1]
    SEROUT rxpin, ANTBaud, [noparse][[/noparse]STR variable2]
    GOTO LOOP2
    
    END
    
    




    I receive the FIRST byte correct ALWAYS but after that, its random... like the 6th works, then suddenly 11th and 18th, and the next run its other random bytes...

    I'm just using different baud rates, codes etc, trial and error kind of, hopefully I can get it to work soon..
  • 4ish4ish Posts: 24
    edited 2005-08-05 23:10
    alright guys nevermind. I got it to work exactly how I wanted it... thanks alot for your help, much appreciated...
Sign In or Register to comment.