Shop OBEX P1 Docs P2 Docs Learn Events
simple serial interface (Solved) — Parallax Forums

simple serial interface (Solved)

Laurent RLaurent R Posts: 27
edited 2009-04-05 16:54 in Propeller 1
Hi

New day = > new problem tongue.gif

I try to put a flow of byte in a buffer using the simple serial interface and the max3430 for rs-485

It works when i send $AAFF13 or $AA13
But if i send more than 3 bytes it doesn't works ...

VAR

  LONG Chan
  Byte Range 
  Byte Bip
  Byte MyStr[noparse][[/noparse]1024]



the way i receive
      ptr:=0
      repeat while (MyStr[noparse][[/noparse]ptr]:=ser2.rx)<>$13
        ptr++



the way i send
ptr2:=0
      repeat ptr+1
       ser2.tx(MyStr[noparse][[/noparse]ptr2])
       ptr2++



Thanks for your help ...

Laurent

Post Edited (Laurent R) : 4/3/2009 7:55:21 AM GMT

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-03-31 16:40
    Hello Laurent,

    the simple serial-object is much too simple to receive a lot of bytes

    use the Serial Mirror-object from the obex

    Inside this object it is easy to adjust the size of the receive and send-buffer

    best regards

    Stefan
  • AribaAriba Posts: 2,690
    edited 2009-03-31 17:05
    Laurent

    SimpleSerial has a bug in the receive methode, maybe this cause your problems.
    Here is an improved version of the rx methode. Only the marked line must be added.

    PUB rx: rxByte | t, b
    {{ Receive a byte; blocks caller until byte received. }}
    
      if rxOkay
        dira[noparse][[/noparse]sin]~                                          ' make rx pin an input
        b~                                                  '<-- ADD THIS
        waitpeq(inverted & |< sin, |< sin, 0)               ' wait for start bit
        t := cnt + bitTime >> 1                             ' sync + 1/2 bit
        repeat 8
          waitcnt(t += bitTime)                             ' wait for middle of bit
          b := ina[noparse][[/noparse]sin] << 7 | b >> 1                       ' sample bit 
        waitcnt(t + bitTime)                                ' allow for stop bit 
    
        return (b ^ inverted) & $FF                         ' adjust for mode and strip off high bits
    
    



    Andy
  • Laurent RLaurent R Posts: 27
    edited 2009-04-01 09:08
    Thanks Andy and Peter but it seems that your answers doesn't work for me...

    I don't undersdand my problem because if i try to look after the CR caracter, it works for 3 Bytes transmission not more
    ptr:=0
          repeat while (MyStr[noparse][[/noparse]ptr]:=ser2.rx)<>$13
            ptr++
    



    But if I try this
    MyStr[noparse][[/noparse]0]:=ser2.rx
    MyStr:=ser2.rx
    MyStr:=ser2.rx
    MyStr:=ser2.rx
    MyStr:=ser2.rx
    MyStr:=ser2.rx
    



    the prop wait that I send 5 caracter and send me back so I know that he has received a CR caracter ..

    Post Edited (Laurent R) : 4/1/2009 9:16:11 AM GMT
  • Laurent RLaurent R Posts: 27
    edited 2009-04-01 10:32
    Hi all

    trying the serial-mirror object i can now receive and send a lot of bytes ... but there is a but, new bytes are always put at the end of my buffer...

    with this code i through that new bytes should begin at MyStr[noparse][[/noparse]0] ... but it isn't.

    ptr:=0
          repeat until (MyStr[noparse][[/noparse]ptr]:=ser2.rx)==$13
            ptr++
    
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-04-01 10:46
    By the way, CR is not $13, it is 13 which is $0D in hex.
  • Laurent RLaurent R Posts: 27
    edited 2009-04-02 10:04
    Thanks MagIO2 it probably help me for the future but it don't solve my problem ... [noparse]:)[/noparse]

    As i initialize all my variable to 0 before doing a new reception i don't understand why old bytes aren't deleted when I receive a new reception ...

    I'm confused so I still need help ...

    Laurent
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-02 11:35
    Hello Laurent,

    als long as your condition is (MyStr[noparse][[/noparse]ptr]:=ser2.rx)==$13
    the condition stays FALSE when receiving a carriage return

    only if you receive ASCII-Code 1*16+3 = 19 the condition will be TRUE

    from your answer it is NOT clear if you made this change
    your condition has to be

    (MyStr[noparse][[/noparse]ptr]:=ser2.rx)==13 'WITHOUT the "$"

    or (MyStr[noparse][[/noparse]ptr]:=ser2.rx)==$0D 'hexedcimal "0D" with the hexdecimal indicator "$"

    If you use the serialmirrror-object and resize your receivebuffer to 1024 bytes or even 16384 bytes if you like
    you just call ONCE rxstr and EVERYTHING IS DONE

    why do you still want to walk on feet with programming a loop

    ptr:=0
          repeat until (MyStr[noparse][[/noparse]ptr]:=ser2.rx)==$13
            ptr++
    
    
    



    if you can drive by car

    using serial-mirror and coding just

      .rxstr(@MyStr)  
    
    
    



    best regards

    Stefan
  • Laurent RLaurent R Posts: 27
    edited 2009-04-02 12:20
    Hi Stefan

    Thanks for your support...

    In the serial-mirror i don't find a rxstr method... so I add it from extended serial object ...

    But I have still the same problem...

    I want to receive a serial command , do a task , send a serial answer and then be able to receive a new command...

    The new command should replace the old and be saved in MyStr but it always saved after the first...

    I can't erase the first one ...

    Regards

    Laurent
  • Laurent RLaurent R Posts: 27
    edited 2009-04-02 12:41
    I hope my problem is solved...

    Just try to stop and restart the serial communication each time I want to receive a new command and it seems to be good [noparse]:)[/noparse]

    thanks @ all

    Laurent

    Post Edited (Laurent R) : 4/2/2009 1:06:35 PM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-02 16:52
    Hello Laurent,

    restart the serial communication that's shooting with canons on little birds

    question: how many bytes are you receiving as ONE STRING as a maximum ?

    I assumed from your original code MyStr[noparse][[/noparse]1024] that you receive up to 1024 bytes as ONE STRING

    if your string-length is below 16 you can use the standard-objects

    ANYWAY:
    did you watch your incoming strings with a terminalsoftware ?
    did you check with a terminalsoftware that your sending device is sending SINGLE commands ?

    I have attached an archive with democode that works with PST.EXE as well as with brays terminal
    using serial-mirror for receiving the string on Rx-Pin 26 and Tx-Pin 25
    and send it to Rx-Pin 31, Tx-Pin 30


    if you want to attach code use the archive-function of the propellertool

    select your top-object-file (here main-test.spin) and then
    cklick file - archive - project...

    this creates a ZIP-file that contains ALL files needed to compile the whole project

    best regards

    Stefan
  • Laurent RLaurent R Posts: 27
    edited 2009-04-03 07:52
    Thanks to you Stehan,

    I don't have to kill little bird with canons now [noparse]:)[/noparse]

    I think the bytefill command and the flush where the answer for me

    Best regards

    Laurent
  • propwellpropwell Posts: 87
    edited 2009-04-05 16:47
    Hi together,

    i'm pretty new in the business with Propeller and Programming in general, but i created a little program in Spin, which creates several lines and shows it on my screen, it works really good.
    But now, i want to read die angles of the lines (which i previously saved in 3 Variables) from a serial connection.
    For the first it would be enough if i could send a value like "180" from a serial terminal to the propeller, the porgram reads it and saves it in a variable!

    Now my questions:
    1. Can i make a serial connection with the USB-Connection which is on the Starter-Kit-Board?
    2. I've downloaded the serialmirror.spin, can i use this one?
    3. Is there something like a tutorial which i can read for not asking you these (surely) stupid questions?

    Thank you,
    propwell
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-05 16:54
    1) Yes, pin 31 is the receive line from the PC and pin 30 is the transmit line to the PC. Be careful since opening and closing the serial connection usually (by default) toggles the DTR line and this will cause the Prop to reset. You need to disable this behavior on the PC side, usually as an option on the serial port.
    2) Yes, you should be able to use any of the serial I/O drivers to do this.
    3) No. Do look at the FullDuplexSerial driver and the Extended FullDuplexSerial object. The latter includes routines for processing input numbers and strings.

    In the future, please start your own thread. You'll get better and faster answers than hijacking someone else's thread.
Sign In or Register to comment.