This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Inputing data through Serial Window is slow

I am writing a code that simulates receiving text from the serial port using the serial window.
When I debug this code step by step and enter the text, it works fine, but when I run the code and enter the text all at once not all of the characters are received!
For example if I want to enter "OK", in debugging step by step I enter O then K and it is perfect. However, when I run the code and type "OK" quickly, I may receive "K" only or nothing at all, while if I type it slowly (which I don't think is the case in serial communication) it is received correctly!
Can you help me with this?
Thank You!

Parents
  • Ain't I using the interrupt in the following code?
    if you want to appear Southern (Ain't ) then do it right!
    "I Ain't using no interrupt in that thar code"

    while(1)
    { while (RI==0);
    buffer= SBUF;
    s1[i]=buffer;
    RI=0;
    if (s1[i]==cr)
    goto End;
    i=i+1;
    } End:
    

    where does this wait for RI being set???
    what is wrong with "break"

    Erik

Reply
  • Ain't I using the interrupt in the following code?
    if you want to appear Southern (Ain't ) then do it right!
    "I Ain't using no interrupt in that thar code"

    while(1)
    { while (RI==0);
    buffer= SBUF;
    s1[i]=buffer;
    RI=0;
    if (s1[i]==cr)
    goto End;
    i=i+1;
    } End:
    

    where does this wait for RI being set???
    what is wrong with "break"

    Erik

Children
  • OK i can remove the goto and put break instead? but this doesn't solve the problem!
    The code is looping while there is no RI set...if it is set we take the input from the SBUF and then set the RI.
    I can't get where is the problem..please explain further :)
    thank you

  • putting break wont solve the problem ... the problem is in the speed not the syntax i guess because it reads it when the input is inserted slowly.. please give me further explanation!
    thank you :)

  • Why should we - for now - ignore your code that tries to move a lot of data? Why are you not doing that incrementally? Every time you receive one character from the serial port, you can place that single character exactly where you need it to be. So no huge extra work when you see a carriage return.

    By the way - why do you have a variable for your carriage return? What was wrong with just using a named constant?

  • "what is wrong with "break""
    OK i can remove the goto and put break instead? but this doesn't solve the problem!
    no, of course not, but it makes your code 'C' instead of "C coded assembler"

    "where does this wait for RI being set???"
    if it is set we take the input from the SBUF and then set the RI.

    there STILL is no wait for RI being set, your words do not change the code

    Erik

  • ""where does this wait for RI being set???"

    Here:

    while (RI==0);
    

    But it would be a whole lot easier to see if the OP took the trouble to properly lay out the code!

    And a few comments wouldn't go amiss; eg,

    while (RI==0); // Wait until RI is set
    

    Comments should also show what the OP intends the code to do - which will allow others to see any flaws in those expectations...

  • Here:

    while (RI==0);
    But it would be a whole lot easier to see if the OP took the trouble to properly lay out the code!

    And a few comments wouldn't go amiss; eg,

    while (RI==0); // Wait until RI is set

    I missed that one because I (once? still?) work(ed) with a debugger that would not set a breakpount on

    while();
    

    but would set one on

    while()
    {
    }
    

    and thus since have 'outlawed' while();

    anyhow, the second form is a lot clearer

    of course, had the OP bothered to comment I would not have missed it.

    Erik

  • More probably, you missed it because no "proper" code should have any actions performed to the right of an opening curly brace.

    With time, we learn pattern patching just as we learn speed-reading normal text based on patterns and not individual characters.

    Anyone posting code that isn't properly tagged and properly indented have waived their right to get any real help.

  • Surely that's a privilege - not a right - anyhow...?