Loading ...
Sorry, an error occurred while loading the content.

HW Serial buffer question

Expand Messages
  • gves2000
    Hi All, This question must be asked many times but I can t find a solution for my problem. Last week I have bought Bert s book wich on many topics helped me a
    Message 1 of 4 , Feb 1, 2009
    • 0 Attachment
      Hi All,

      This question must be asked many times but I can't find a solution for
      my problem.

      Last week I have bought Bert's book wich on many topics helped me a lot.

      My problem is the following. I need to read commands from the serial
      port. These commands consists of about 5 characters, always starting
      with ':' and ending with '#'.

      When I try the following code characters are lost.

      -- Lees seriele data
      while Serial_HW_Read(serIN) loop
      pin_d1 = low
      serial_hw_write(">")
      serial_hw_write(serIN)
      serial_hw_write("<")
      print_crlf
      value_changed = true
      end loop

      The program (JAL241 with _bert libs) is running on a 16F877 on 20Mhz.
      The speed is 9600 and a max232 is used.

      Can someone point me in the right directions?

      Thanks,
      Ge
    • Joep Suijs
      ... Hi Ge, What you do is send 5 chars, when you receive one. This is okay if the received chars have enough idle time inbetween. If not, you run into trouble,
      Message 2 of 4 , Feb 1, 2009
      • 0 Attachment
        --- In jallist@yahoogroups.com, "gves2000" <gves2000@...> wrote:
        >
        > When I try the following code characters are lost.
        >
        > -- Lees seriele data
        > while Serial_HW_Read(serIN) loop
        > pin_d1 = low
        > serial_hw_write(">")
        > serial_hw_write(serIN)
        > serial_hw_write("<")
        > print_crlf
        > value_changed = true
        > end loop
        >

        Hi Ge,

        What you do is send 5 chars, when you receive one. This is okay if
        the received chars have enough idle time inbetween. If not, you run
        into trouble, since - regardless of the baudrate - sending *5* chars
        takes 5 times as much time as receiving *1*.

        So what can you do:
        - only send (max) one char fore each received char.
        - put idle time after each char you send
        or
        - take an interrupt-based serial lib (like serial_hw_int_cts.jal from
        jallib; such a lib queues some chars, default 32 on receiving and 64
        on sending), so you don't loose chars that quick.

        Joep
      • Bert van Dam
        Hi Ge, ... Thanks for buying my book! ... The hardware buffer is only two bytes. So if new data arrives while you are still sending, then anything over two
        Message 3 of 4 , Feb 1, 2009
        • 0 Attachment
          Hi Ge,

          >Last week I have bought Bert's book wich on many topics helped me a lot.

          Thanks for buying my book!

          >My problem is the following. I need to read commands from the serial
          >port. These commands consists of about 5 characters, always starting
          >with ':' and ending with '#'.
          >
          >When I try the following code characters are lost.
          >
          >-- Lees seriele data
          >while Serial_HW_Read(serIN) loop
          >pin_d1 = low
          >serial_hw_write(">")
          >serial_hw_write(serIN)
          >serial_hw_write("<")
          >print_crlf
          >value_changed = true
          >end loop
          >

          The hardware buffer is only two bytes. So if new data arrives while you are
          still sending, then anything over two bytes will be lost.

          So you need to first read all characters from the command (you know when
          you're done because the last character will be #) and then send your reply.
          During that time no new command must be send.

          Have fun,
          Bert

          www.vandam.tk
        • gves2000
          Joep, Bert, Thanks for your replies. The commands are sent by an external device so increasing the interval between chars isn t possible. I will give both your
          Message 4 of 4 , Feb 1, 2009
          • 0 Attachment
            Joep, Bert,

            Thanks for your replies.

            The commands are sent by an external device so increasing the interval
            between chars isn't possible.

            I will give both your suggestions a try.

            Ge





            --- In jallist@yahoogroups.com, "Bert van Dam" <bymco.bv@...> wrote:
            >

            >
            > The hardware buffer is only two bytes. So if new data arrives while
            you are
            > still sending, then anything over two bytes will be lost.
            >
            > So you need to first read all characters from the command (you know
            when
            > you're done because the last character will be #) and then send your
            reply.
            > During that time no new command must be send.
            >
            > Have fun,
            > Bert
            >
            > www.vandam.tk
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.