We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
The same buffer I'm using for transmitting the application dependent internal status message
This is dangerous. Can it be that you suffer from a race condition between receiving a command (interrupt based I guess) and sending your application status...? It would be better to associate these operation with different buffers.
It can work quite ok with a shared buffer, if the serial interrupt knows about framing characters in the received message, and can ignore reception of new characters until an answer has been sent, or until the main application has flagged that the received message is broken - in which case it might be good to design the protocol with a NACK message.
To do it without any synchronization can lead to very hard-to-catch problems.
Thank you very much for your message.
Actually I'm using polling method of message reception not Interrupt method.
I have used two buffers of size arr[35] arr1[35] one for Txd and other for Rxd. There also same behavior.
In this method it was working when im keep on reciving the message that means i'm using only arr[35] buffer.
At the moment i started using the second buffer arr1[35] for transmitting. Its transmitting the message correctly and cpu hangs. only way i have to reset the controller.
I think there is some severe memory overflow/system stack overflow happens when we are using array of characters.
Expecting some suggestions. Thanks.
Thanks.
Exactly,
I'm not using any synch mechanism here. Whatever message comes in Im receiving it and processing the message. Note that its loop of 35 characters. Im interseted only first 35 characters. after processing the message i'm transmitting the status.
I cant use any synch mechanism here because the message will vary every time its not in my control. I'm intersted in only first 35 chars in that i will searc for my command string is available or not with a encapsulation of special characters like @,#,$ etc.
Please suggest.
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?
HAVE YOU SEEN THE KNOWLEDGE BASE FOR COMPILAR BUGS>?
DO YOU IDE USE THE OLD VERSION?
ANY ERRORS!
Exactly why would screaming help?
Anyway - do not use variable names arr and arr1. They are meaningless. What are the buffers? rx_buf[] and tx_buf[] or do you have two two receive buffers?
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 }
} }
re-post using the proper tags please!
Please see my code in the previous thread.
Thanks
SEE
(i=0;i<=35;i++)
BUFFER IS
xxx[35]
YOU ARE GOUNNG TOOO FAR!
Anyway - do not use variable names arr and arr1. They are meaningless.
... unless you're a pirate.
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)
Request[j]= 'B';
Send_Str(Request);
} } }
YOURE POSTED CODE IS STILL WRON GSEE MY LAST ANSWRE!
Please post a link to your previous thread then. There is no button to move to the next/previous thread written by you.
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!