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

Memory overflow problem

Hi all,

I'm using 89C52 controller in my application. I'm using a 90 byte buffer to store received message from UART. Based on this received message I'm controlling I/O ports. The same buffer I'm using for transmitting the application dependent internal status message.

To identify the message I'm using absolute address position for example, if(arr[59] == '*'){do something;}

every first message after reset this is working fine. After that the control hangs somewhere thus its giving undetermined behavior.

I set the memory model as Large: all variables in XDATA.

I hope some address overflow is happening here.

Can anyone help me to resolve this issue.

Thanks in Advance.

Regards,
Ramesh

Parents
  • I think there is some severe memory overflow/system stack overflow happens when we are using array of characters.

    but how can you see so sure about this? many other issues can be the cause. did you try to strip your program of everything which is not absolutely necessary (as your problem can be triggered by an interaction of some kind)? does you controller finish handling a message in one polling cycle (if not, maybe you overwrite not-yet-processed data)? can you post clear and outlines code related to the problem?

Reply
  • I think there is some severe memory overflow/system stack overflow happens when we are using array of characters.

    but how can you see so sure about this? many other issues can be the cause. did you try to strip your program of everything which is not absolutely necessary (as your problem can be triggered by an interaction of some kind)? does you controller finish handling a message in one polling cycle (if not, maybe you overwrite not-yet-processed data)? can you post clear and outlines code related to the problem?

Children
  • Here is my code fragment:

    #include<serial.h>
    #include <AT89X52.H>
    unsigned char message[35];
    unsigned char Request[35]; main()
    { unsigned char i,j,;

    Init_Uart(); // UART functionlity working fine with 9600 baud while(1) { for(i=0;i<=35;i++) { message[i]=RX_CHAR(); //Rx buffer for first 35 char's controll waits here for incoming char process=1; }

    if(process==1) {

    if(message[25]=='*') // I'm sure that this characters are 26th character always from transmitter {pass =1; TestLED=ON;} else if(message[25]=='#') {pass =0;TestLED=OFF;} process =0; }

    if(pass==1) { for(j=0;j<=35;j++) { Request[j]= 'A';

    } Send_Str(Request); // Request array is transmitted Note this subroutine is tested working correctly

    } else if( pass==0) { for(j=0;j<=35;j++) { Request[j]= 'B';

    } Send_Str(Request); // Request array is transmitted }

    } }

    Please suggest.

  • Here is the code again..

    #include<serial.h>
    #include <AT89X52.H>

    unsigned char message[35];
    unsigned char Request[35];

    main()
    { unsigned char i,j;

    // UART functionlity working fine with 9600 baud

    Init_Uart();
    while(1)
    { for(i=0;i<=35;i++)

    {

    //Rx buffer for first 35 char's
    // controll waits here for incoming char

    message[i]=RX_CHAR();
    process=1;

    }

    if(process==1)

    {

    // I'm sure that this characters are 26th
    // character always from transmitter

    if(message[25]=='*')

    {

    pass =1;
    TestLED=ON;

    }

    else if(message[25]=='#')

    {

    pass =0;
    TestLED=OFF;

    }

    process =0;

    }

    if(pass==1)

    {

    for(j=0;j<=35;j++)

    {

    Request[j]= 'A';

    }

    // Request array is transmitted Note this
    // subroutine is tested working correctly.

    Send_Str(Request);
    }

    else if( pass==0)

    {

    for(j=0;j<=35;j++)

    {

    Request[j]= 'B';

    }

    Send_Str(Request);

    }
    } }

    Thanks

  • unsigned char message[35];
    unsigned char Request[35];
    
    for(i=0;i<=35;i++)
    {
    
    //Rx buffer for first 35 char's
    // controll waits here for incoming char
    
    message[i]=RX_CHAR();
    process=1;
    
    }
    
    for(j=0;j<=35;j++)
    
    {
    
    Request[j]= 'A';
    
    }
    
    

    YOU ARE FILLIN G A 35 CHARACTER ARRAY WIT H36 CHARACTERS!

    THAT IS OVERFLOW!

  • narak,
    don't you think it is only appropriate to also SCREAM in the code that you post?!

  • <QUOTE>don't you think it is only appropriate to also SCREAM in the code that you post?!</QUOTE>

    HE DOES NOT WANT TO LISTEN TO MY ANSWER WHO I THINK IS CORRE CT!

    IS HE DEF?

  • the OP probably already implemented your careful advise. there is no need to use UPPERCASE. that won't make his listen - just annoy everyone else.

  • Hi Narak,

    I had already modified the code as below. But still its not working.

    for(i=0;i<=34;i++) { message[i]=RX_CHAR();

    }

    I'm using Uvision3 IDE version 3.30a. I have not tried out with older version of IDE. Will it cause any problem??