Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/13/07 19:26
Read: times


 
#132821 - Serial HUNG.
Hello, I have a problem of serial communication of a microcontroller AT89S52 and a visual application, the problem it is that in random form it is hung and the communication with the application is lost I have proven recharging the parametros before each communication is not equal is hung suddenly without being able to identify the reason, the unica form to recover the communication reseteando the card and works well. Data: I am using a converter of USB to Serial for coneccion to the PC.

Thanks.


#include <Reg52.h>
#include <stdio.h>
char uart_data;
void Entrada1();
void Entrada2();
void Salida1();
void Salida2();
void time1();
void iniserial();
sbit s1 = P2^0;
sbit s2 = P2^1;
sbit s3 = P2^2;
sbit s4 = P2^3;
long int E1;
long int S1;
long int E2;
long int S2;
long int t1;
long int t2;

void main(void)
{

#ifndef MONITOR51
SCON = 0x52;
TMOD |= 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
TI = 1;
ES = 1;
EA = 1;

#endif

printf ("\n0,0,0");

while(1);
}
void serial_IT(void) interrupt 4
{
if (RI==1)
{
RI = 0;
uart_data = SBUF;
if(uart_data==0x30)
{
E1 = 0;
E2 = 0;
S1 = 0;
S2 = 0;
printf ("\n0,0,0");
}
}

if(s1==0)
{ while(s2==1);
while(s1==0 || s2==0);
Entrada1();
}

if(s2==0)
{ while(s1==1);
while(s1==0 || s2==0);
Salida1();
}

if(s3==0)
{ while(s4==1);
while(s3==0 || s4==0);
Entrada2();
}

if(s4==0)
{ while(s3==1);
while(s3==0 || s4==0);
Salida2();

}
}




void Entrada1(void)
{ E1++;
time1();
iniserial();
printf ("\n1,1,%li",E1);
if (s1==0);
s1 = 1;
if (s2==0);
s2 = 1;
}
void Salida1(void)
{ S1++;
time1();
iniserial();
printf ("\n1,2,%li",S1);
if (s1==0);
s1 = 1;
if (s2==0);
s2 = 1;
}
void Entrada2(void)
{ E2++;
time1();
iniserial();
printf ("\n2,1,%li",E2);
if (s3==0);
s3 = 1;
if (s4==0);
s4 = 1;
}
void Salida2(void)
{ S2++;
time1();
iniserial();
printf ("\n2,2,%li",S2);
if (s3==0);
s3 = 1;
if (s4==0);
s4 = 1;
}
void time1(void)
{
for(t1 = 0; t1<=10000; t1++);
}

void iniserial(void)
{
#ifndef MONITOR51
SCON = 0x52;
TMOD |= 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
TI = 1;
ES = 1;
EA = 1;
#endif
}

List of 10 messages in thread
TopicAuthorDate
Serial HUNG.            01/01/70 00:00      
   how does printf work?            01/01/70 00:00      
   I can not read your code without spending            01/01/70 00:00      
      not quite... :-)            01/01/70 00:00      
         Outside ISR            01/01/70 00:00      
            then keep learning            01/01/70 00:00      
               Not help me            01/01/70 00:00      
                  While ...            01/01/70 00:00      
                  why will you not help me help you?            01/01/70 00:00      
   Maybe your code is OK            01/01/70 00:00      

Back to Subject List