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

UART PROBLEM ARM lpc1769

I want change easyweb to communicate with the camera and send hex data (camera) up through enthernet computer.
I used the arm to connect to the camera via uart, but my problem is getting data from the camera with a piece of lost data when I put the counter(nn) above 315bytes.
my camera send data HEX about 12kb.
What is my problem?
way to solve?
my code received data from camera: while(1){ pdata[nn] = UARTGetChar(LPC_UART0);

if (nn==280)(break;}

nn++; }

Parents
  • Are you making fun of us?

    Did you think your code looked good? No indentation?

    Do you _really_ write code looking like:

    if (nn==280) { break;
    
    }
    


    Not even:

    if (nn==280) {
        break;
    }
    

    Or did you just copied the already broken code (resulting from you not caring about my first post suggesting how to post source code) and reposted it again - without noticing that it still looked like a mess?

    One issue with your code - having a single loop to receive all data over UART takes time. During that time, you don't service the TCP/IP stack.

    You really should consider having interrupt-based UART communication that can happen concurrently with other things and then make the TCP communication when you have performed a correct transfer from the camera.

    Another thing - why do you love global variables so much. The code is full of assigns to variables that are neither local or parameters to the function. Variable scope was invented because it greatly increases the readability and maintainability. Maintainability - the ability to see what code does and modify code without breaking it.

    Your code don't do any error handling.

        ...
        // *** How do you know this function, that you say will send, really will send???
        transmit();//Here is a function to send the data from the camera to the computer via LAN
    
        return;
    }
    
    void transmit(void) {
        if (SocketStatus & SOCK_CONNECTED) {
            if(SocketStatus & SOCK_TX_BUF_RELEASED) {
                memcpy(TCP_TX_BUF,pdata,nn);
                TCPTxDataCount=nn;
                TCPTransmitTxBuffer();
                free(pdata);
            }
        }
    }
    


    Notice that transmit() have two if statements. Only if you pass them will you get into the code that seems to transmit - how is your UART code (that allocates a buffer for the incomming data) take this into account?

    Start looking at the TCP/IP examples.
    Then start trying to "unmess" your code a bit.
    Keep track of the current state.
    Make sure that functions returns error results if they may fail.
    Make sure that you always check error results.
    Try some debugging, to compare where you assumptions deviates from what the program actually do.

    And when you post code next time - make sure it does look readable.

Reply
  • Are you making fun of us?

    Did you think your code looked good? No indentation?

    Do you _really_ write code looking like:

    if (nn==280) { break;
    
    }
    


    Not even:

    if (nn==280) {
        break;
    }
    

    Or did you just copied the already broken code (resulting from you not caring about my first post suggesting how to post source code) and reposted it again - without noticing that it still looked like a mess?

    One issue with your code - having a single loop to receive all data over UART takes time. During that time, you don't service the TCP/IP stack.

    You really should consider having interrupt-based UART communication that can happen concurrently with other things and then make the TCP communication when you have performed a correct transfer from the camera.

    Another thing - why do you love global variables so much. The code is full of assigns to variables that are neither local or parameters to the function. Variable scope was invented because it greatly increases the readability and maintainability. Maintainability - the ability to see what code does and modify code without breaking it.

    Your code don't do any error handling.

        ...
        // *** How do you know this function, that you say will send, really will send???
        transmit();//Here is a function to send the data from the camera to the computer via LAN
    
        return;
    }
    
    void transmit(void) {
        if (SocketStatus & SOCK_CONNECTED) {
            if(SocketStatus & SOCK_TX_BUF_RELEASED) {
                memcpy(TCP_TX_BUF,pdata,nn);
                TCPTxDataCount=nn;
                TCPTransmitTxBuffer();
                free(pdata);
            }
        }
    }
    


    Notice that transmit() have two if statements. Only if you pass them will you get into the code that seems to transmit - how is your UART code (that allocates a buffer for the incomming data) take this into account?

    Start looking at the TCP/IP examples.
    Then start trying to "unmess" your code a bit.
    Keep track of the current state.
    Make sure that functions returns error results if they may fail.
    Make sure that you always check error results.
    Try some debugging, to compare where you assumptions deviates from what the program actually do.

    And when you post code next time - make sure it does look readable.

Children