Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hallo evreyone,
I am a beginner doing projects with TTN
Currently I am working with Microchip SAMR34.I was trying to do a project where it reads the entered number and dsiplays it, The enetred number can be seen using an Emulator. I have used TeraTerm for this purpose.

The serial Data handler given in the example Project reads only one character, I have modified the code in such a way it reads more than one character at a time.The value received is stored int to a buffer SerialBuffer, But once number is entered for join request, its stops the application process and doesnot moves further.

The code given below is form the example project:

C++
static char SerialBuffer;

void serial_data_handler(void)
{
    int rxChar;
    char serialData;
    /* verify if there was any character received*/
    if (startReceiving == true)
    {
        if((-1) != (rxChar = sio2host_getchar_nowait()))
        {
            serialData = (char)rxChar;
            if((serialData != ‘\r’) && (serialData != ‘\n’) && (serialData != ‘\b’))
            {
                startReceiving = false;
                serialBuffer = rxChar;
                appPostTask(PROCESS_TASK_HANDLER);
                printf("\r\n");
            }
        }
    }
}


What I have tried:

what i have tried: But it is not working !
C++
void serial_data_handler(void)
{
    // uint8_t rxChar;
    char serialData;
    char arr[10];
    char recv;
    int i = 0;
    int value;
    recv = 0x00;

    /* verify if there was any character received*/
    if (startReceiving == true)
    {
        while(('\n' != recv)&&('\r' != recv) && ('\b' != recv))
        {
            recv = sio2host_getchar();
            arr[i] = recv;
            i++;		
        }
        //startReceiving = false;
        value =(int)atoi(arr);
        serialBuffer = value;
        appPostTask(PROCESS_TASK);
    }
}
if anyone has any idea, please share . It would be a great help!

Thanks
Posted
Updated 8-Oct-19 6:30am
v5

1 solution

A few things are notable to me.

1: You do not initialize the value of recv. It probably should be set to 0 to be certain it enters your while loop at least once.

2: Your array buffer arr is of size 10 but you could potentially receive more than ten characters because the loop doesn't care how many you get. That could be a very bad thing.

3: atoi expects a null-terminated string. You should make sure a null character is at the end of that string. That does not appear to happen with your code.

4: The example code is calling sio2host_getchar_nowait() and yours is calling sio2host_getchar(). Those are not the same thing. You should probably make sure you are calling the right function. If I were to guess, it would appear you are calling a blocking version.
 
Share this answer
 
Comments
KarstenK 9-Oct-19 2:08am    
Great answer, I hope the asker is understanding all points. :-)
Member 14499788 9-Oct-19 2:14am    
Thankyou for your valuable suggestions. I will try doing the same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900