PIC18F252 UART lock after 3-4 hours of working

General discussion on mikroC.
Post Reply
Author
Message
rainalert
Posts: 1
Joined: 07 Jan 2011 10:02

PIC18F252 UART lock after 3-4 hours of working

#1 Post by rainalert » 07 Jan 2011 10:31

Hi,

i am working on a wireless thermometer. I have DS1820 and PIC16f688 on the transmitter side. The transmitter sends the temperature data as a serial data of "$E000.0000$B" then sleep for 33 second. After that the receiver wakes up and then sends the preamble data+temperature data again. While transmitter sleeps there is a lot noise on the receiver side and framing error occurs. The receiver checks OERR and FERR for overrun and framing error. If one of them exists then receiver try to clear them in interrupt routine.

The problem is that UART locks after 3-4 hours of working. I'm sure the PIC main loop still works because scanning the 7 segment display works and shows the last correct reading of the temperature. However there is no incoming data although the transmitter sends the data. Make a reset on receiver side starts the receiver again for 3-4 hours.

I tried to move error checking to the main loop and it did not work.

My question are:

-does FERR or OERR generate an interrupt or only a received byte without error generate an interrupt?
-why the code works only 3-4 hours (300-400 readings)?
-should i check the error both in main loop and in interrupt routine or only one of them is ok.

Recevier and transmitter side has ASK 433Mhz RF modul.
Receiver side microcontroller has PIC18F252.
Both receiver PIC and transmitter PIC are clocked with 20Mhz Xtal.

Regards,

Mesut

Code: Select all

void interrupt() //Receive interrupt
{

while (PIR1.RCIF==1)
{

if (RCSTA.OERR==1) //Cheching overrun error if exists then clear
{
RCSTA.CREN = 0;
asm nop;
RCSTA.CREN = 1;
}

if (RCSTA.FERR==1) //Checking frame error if exists read a byte to clear
{
tmp=UART1_Read();
continue;
}

tmp=UART1_Read(); //if there is not an error continue

if (pre_tmp==0x24 && tmp==0x45 && receive_flag==1)
{
text[count]=0;
receive_flag=0;
status_flag=1;
}

else if (pre_tmp==0x24 && tmp==0x42 && receive_flag==0)
{
receive_flag=1;
status_flag=0;
count=0;
}

else if (receive_flag==1)
{
text[count]=tmp;
count++;
status_flag=0;
}
pre_tmp=tmp;
}

}


void main() {


INTCON=0b10000000;  // High priority interrupts are on
RCON.IPEN=1; // High-low interrupt is active
IPR1.RCIP=1; // UART receive interrupt is set as high priority
PIE1=0b00100000; // UART receive interrupt is set
ADCON1=0b00000111; // ADC is off
CCP1CON=0; // Comparators are off
CCP2CON=0; 

TRISB=0; 
TRISC=0b10000000; 
TRISA=0; 
LATA=0; 


Delay_ms(100);

UART1_Init(1200); // setting baud rate
Delay_ms(100); // stabilization

pre_tmp=0;
receive_flag=0;
status=0;
sicaklik=10000;


while(1)
{


if (status_flag==1) sicaklik=atof(text); // convert received data to float 
ss_sayi_yaz(sicaklik,1); // show temperatur on 4 digit 7 segment display

}


}

Post Reply

Return to “mikroC General”