[En-Nut-Discussion] serial communication receive task hangup

Peter Sodermanns peter.sodermanns at aixcon.de
Wed Jul 26 11:10:10 CEST 2006


Hi group,

my data logger application based on Ethernut 2.1b from time to time 
stops serial communication. It gets every 3 minutes data from another 
device connected to RS232 port 2. Longest period of flawlessly working 
is 14 days, mostly it stops after 2..3 days.
Since the other tasks keep working I think it's an application problem, 
but I wouldn't exclude a hardware problem either - maybe distorting 
pulses on the connected wire (about 15 m of length).
I'm using WinAVR-20060421 and Ethernut 4.0.3.

I would appreciate very much if someone could take a look on my source 
below. Maybe another person sees at first glance where the mistake is:

//-------------------------------------------
// Receive-Task
//-------------------------------------------
THREAD(WR_Receive_Service, arg) {
static u_char c;
static u_char beginOfLine=0;
static u_int len=0;
static u_int i;
static u_int j;
static u_int count;

   // highest priority
   NutThreadSetPriority(48);
   i = 0;

   for (;;) {
     count = 0;
       i = fgetc(uart1_stream);
     if (i) {
       for (;;) {
         c = i;
         if (0==beginOfLine){
           // message starts with minus sign
           if ('-'==c) beginOfLine=1;
           len=0;
         }else{
           if (len<sizeof(gv.line)){
             gv.line[len++]=c;
           }else{
             beginOfLine=0;
             len=0;
             gv.line[0]=0;
           }
           // received end of line?
           if ((10==c)||(13==c)) {
             count++;
             // cut after CR
             gv.line[len]=0;
             // 3..170 chars
             if (len > 2) {
               handleAnswer(gv.line, len);
             }
             // delete received line
             for (j=0; j<len; j++)
               gv.line[j] = 0;
             beginOfLine=0;
             len=0;
           }
         }
         i = fgetc(uart1_stream);
         NutThreadYield();
       }
     }
     NutThreadYield();
   }
}


Thankful for any hint,

           Peter




More information about the En-Nut-Discussion mailing list