Connect with us

PIC32 read feedback from UART

Discussion in 'General Electronics Discussion' started by crystal please, Nov 16, 2016.

Scroll to continue with content
  1. crystal please

    crystal please

    10
    0
    Jul 5, 2016
    I'm using a PIC32MX795F512H to set up a Roving RN-131 wifi module using UART.

    I can communicate with the device but I want some feedback whether my commands are processed or not.

    I basically need to check a string the WiFi module returns. The first time I check, it works, the second time, it's not doing anything anymore.
    Code:
    int connected()
    {
        char receiverbuffer[50];
        char CMD[] = "CMD";
        char AOK[] = "AOK";
        int done = 0;
        int connected = 0;
        char str[250];
        putsUART1("$$$");
        memset(str,0,250*sizeof(char));
        memset(receiverbuffer,0,50*sizeof(char));
        while(!done)
        {
            while(U1STAbits.URXDA)
            {
                getsUART1(50, receiverbuffer, 123);
                U1STAbits.URXDA = 0;
                U1STAbits.OERR = 0;
                sprintf(str, "%s%s", str, receiverbuffer);
                memset(receiverbuffer,0,50*sizeof(char));   //Clears the buffer
            }
            if(!strcmp(str,CMD))
            {
                LATBbits.LATB7 = ~LATBbits.LATB7;
                done = 1;
                strcpy(str, "");
                memset(str,0,250*sizeof(char));
            }
        }
        done = 0;
        putsUART1("show con\r\n");
        while(!done)
        {
            while(U1STAbits.URXDA)
            {
                getsUART1(50, receiverbuffer, 123);
                U1STAbits.URXDA = 0;
                U1STAbits.OERR = 0;
                sprintf(str, "%s%s", str, receiverbuffer);
                memset(receiverbuffer,0,50*sizeof(char));   //Clears the buffer
            }
            if(!strcmp(str, CMD))
            {
                LATBbits.LATB7 = ~LATBbits.LATB7;
                done = 1;
                connected = 1;
                memset(str,0,250*sizeof(char));
            }
        }
        putsUART1("exit\r\n");
    
        return connected;
    }
    Any help would be welcome. I think I'm not clearing the string correctly but I have no idea why.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-