Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4064370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:50:50+00:00 2026-05-20T15:50:50+00:00

I am trying to modify a function to be more sensible for my purposes;

  • 0

I am trying to modify a function to be more sensible for my purposes;

int getc0 (void)
{
    while ( (U0LSR & 0x01) == 0 ); //Wait for character
    return U0RBR;
}

The above code causes the function to hang until a character is received on serial port 0 and then returns it.
I was calling it using a while loop like so;

while((str = getc0())!='\r'){
    strcat(&route_buffer,&str);
}

So now I have it waiting until a return carriage is received over the serial port and each character before this is copied into a buffer.
Now my problem, I am having some issues with reading data in at the moment and I cannot determine where the problem lies, either way it is not recognising return carriages or newlines correctly, but it is picking up on some output!
I know this as I have it saving everything to a file once it completes, but to do this I have to have a i!=5 on the while loop and just read in 5 characters. If I do it to 20 it hangs again and appears to not be reading anything else (Even though I am sending data over uart)

Is there a way I can modify it to read for X amount of time and then continue with the rest of the function?

Edit:

char route_data[512], route_buffer[200];

Edit 2:

char *str;

Ok, here is a function I wrote to read in user input;

char* readInput(void){

    userinput = 0;
    str = 0;

    while((str=getc0())!='\r'){
        strcat(&userinput,&str);

    }
    return &userinput;

}

and it is called like so;

strcat(config.nodeid,readInput());

It is called a lot but that is one example of how i call it. I then output this to a file and it works 100% of the time.

It would probably help to explain the whole problem;
I have an ARM board with a wireless module attached to the serial port (RX and TX). The readInput function above is used to read input from a user who has telnet’ed into the wireless module and enables the ARM board to read all input from the user.
What I am trying to achieve now is to read the input from the wireless module after executing a command on it. Using a printf statement I can execute commands by putting the command into the statement. What I need to acomplish is to read in the output from the wireless module, this is where I am having difficulties. I am getting some output but it is very limited and not what expected, but it is clearly something from the module.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:50:50+00:00Added an answer on May 20, 2026 at 3:50 pm

    str is not a nul terminated string passing its address to strcat() will concatenate an indeterminate amount of data to route_buffer.

    Using strcat() is a bad idea in any case for a number of reasons, and your usage is especially ill-advised. You have no protection against buffer overrun, and strcat() must needlessly redetermine the length of the string in route_buffer every time it is called.

    A marginally better solution would be:

    int index = strlen(route_buffer) ;
    int ch ;
    while( index < sizeof(route_buffer) - 1 && (ch = getc0()) != '\r')
    {
        route_buffer[index] = ch ;
        index++ ;
    }
    route_buffer[index] = 0 ;
    

    I have made a number of assumptions from your original code here, such as route_buffer is in fact a nul terminated string. Those are your design decisions; they may or may not be correct or good ones.

    A better solution to your problem would be to put the received characters in a ring buffer from a UART Rx interrupt handler, then have read functions take their data asynchronously from the buffer. You could then easily implement blocking, baulking and timeout access if necessary. You could even have the ISR count the number of newlines buffered so you would know in advance how many lines were available in the buffer. The buffering would also allow your code to not have to worry about servicing the UART in time to prevent a character overrun and data loss.

    If you want timeout behaviour, both the while loop in getc0() and the line input loop must additionally test some timer source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to modify a wordpress / MySQL function to display a little
I'm trying to slightly modify a wordpress template. At the moment a function returns
I'm currently trying to modify some HttpWebRequest functions, but I can't do it through
I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
I'm trying to modify the class of an element if an ajax call based
I am trying to modify the output stream to search/replace some XHTML tags returned
I'm trying to modify the contents of an MSI file using Powershell. To do
I'm trying to modify the UI of a Redmine installation (Redmine 0.7.3.devel.2093 (MySQL)). When
I'm trying to determine how to modify SAP R/3 package code of an installed
This is someone elses code that I am trying to understand and modify... The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.