CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem when using Timer0 Interrupt in RDA interrupt !!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

Problem when using Timer0 Interrupt in RDA interrupt !!!
PostPosted: Fri Mar 30, 2012 6:08 am     Reply with quote

Hi every one.
My problems is using timer0 interrupt inside RDA interrupt, my code is recieve character from rs-232 (in RDA interrupt programe) to check condition, if condition is true, jump to timer 0 interrupt to perform.
Here is my code :
Code:

#int_rda
void ngat_gprs(void)
{
   char c1;
   c1=fgetc(ID1);
   switch (c1)
   {
      case 10:    {
                     indexx=0; 
                  }
                  break;
      case 13:    {
                     chk_gprs=0;
                     check_connect();                 
                  }
                  break;
      default:    {
                     connect_buffer[indexx]=c1;
                     indexx++;
                  }
                  break;
   }
   
}
//------------------------------------------------------------------------------
void check_connect(void)
{
   if (     (connect_buffer[0]=='C')&&(connect_buffer[1]=='O')&&(connect_buffer[2]=='N')
         && (connect_buffer[3]=='N')&&(connect_buffer[4]=='E')&&(connect_buffer[5]=='C')
         && (connect_buffer[6]=='T')&&(connect_buffer[8]=='O')&&(connect_buffer[9]=='K'))
   {         
            chk_gprs=1;
            indexx=0; 
   }
   else {};
}


#int_timer1
void update_check(void)
{
      if (chk_gprs==1)
        {
           
                   fprintf(ID1,"AT+CIPSEND=%d\r\n",length_gps);
                   delay_ms(500);
                   fprintf(ID1,"%s \n",gps_str);
                   delay_ms(500);
           
        }     
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void init_gprs(void)
{   
   fputs("AT+CIPSHUT\n",ID1);
   delay_ms(1000);
   fputs("AT+CIPSTART=\"TCP\",\"113.165.52.122\",\"2020\"\n",ID1);
   delay_ms(1000); 
}

void main(void)
{
   TRISA=0;
   TRISB=0;
   TRISJ=0;
   TRISE=0;
   TRISD=0;
   TRISH=0;
   TRISG=0X04; //rs232
   TRISC=0X80; //rs232
   PORTJ=0;
   PORTE=0;
   PORTD=0;
   
   setup_timer_1(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_BIT);
   set_timer1(0);
   
   enable_interrupts(int_rda2);
   enable_interrupts(int_rda);
   enable_interrupts(int_timer1);
   enable_interrupts(global);
     
   lcd_init(); 
   lcd_gotoxy(3,1);
   printf(lcd_putc,"GPS Tracking");
   lcd_gotoxy(3,2);
   printf(lcd_putc,"HAC Solutions ");
   delay_ms(3000);
   LCD_MoveLeft(20);   
   lcd_putc("\f");
 
 
while (1)
   {
        init_gprs();
   }
}

when i send character from Hyper Terminal to Pic, ("CONNECT OK"), but program not jump to update_check programe(int_timer0) to do.
Please show errors in my code.
thnks+regards.
_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 6:47 am     Reply with quote

You use both delays and print statements in your ISR. Aside from being pretty bad form, I wonder if the compiler is disabling interrupts in your main when you call those same functions. If it is, it is possibly your INT_RDA isr is missing data.

Have you verified that the PIC got the entire CONNECT string?

Also, you enable interrupts for RDA2, but don't have an ISR...not a good idea usually.
Bill Havins



Joined: 20 Nov 2006
Posts: 14
Location: Texas

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 6:49 am     Reply with quote

Which PIC are you using?
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Mar 30, 2012 11:53 am     Reply with quote

jeremiah wrote:
You use both delays and print statements in your ISR. Aside from being pretty bad form, I wonder if the compiler is disabling interrupts in your main when you call those same functions. If it is, it is possibly your INT_RDA isr is missing data.

Have you verified that the PIC got the entire CONNECT string?

Also, you enable interrupts for RDA2, but don't have an ISR...not a good idea usually.


Hi Jeremiah !
Thanks for your reply.
Main purpose of my code is using timer 0 interrupt to always check conditon (in check_connect program ) and have must send data through rs232 (I used printf () command).
Oh, You tested with "CONNECT OK" and will be test with "CONNECT" soon Smile
Thank you Smile
_________________
Begin Begin Begin !!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Mar 30, 2012 11:54 am     Reply with quote

Bill Havins wrote:
Which PIC are you using?

Hi Bill Havins.
Thanks for your reply.
I used Pic 18F97J60 (2 uart port).
Thanks.
_________________
Begin Begin Begin !!!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Mar 30, 2012 9:13 pm     Reply with quote

never use a printf in an interrupt
that is a code wrecker
iporboon



Joined: 29 Mar 2012
Posts: 2

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 10:57 pm     Reply with quote

Did you check that RDA interrupt worked correctly and chk_gprs=1 when you sent the desired string? Maybe use LED toggle.
Did you check that TIMER1 periodic interrupt worked correctly?
And you should clear the chk_gprs flag in the update_check function , not in the ngat_gprs function.
printf should not be the problem if you did not use TBE interrupt enable.
yamenn



Joined: 14 Jun 2014
Posts: 10

View user's profile Send private message

PostPosted: Sat Jun 14, 2014 7:52 am     Reply with quote

I have the same problem.
I am trying to get GPS DATA using RDA interrupt and using Timer0 interrupt for alarm.
I can't use the both interrupts in the same time.
Any ideas ? Wink
yamenn



Joined: 14 Jun 2014
Posts: 10

View user's profile Send private message

PostPosted: Sat Jun 14, 2014 7:57 am     Reply with quote

Code:

#include <18f452.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code protected from reading
#FUSES NOBROWNOUT //No brownout reset
//#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20M)

#use rs232(baud=4800, xmit=PIN_C6,rcv=PIN_C7)

#include <lcd11.c>

#include <stdlib.h>

#int_RDA
void  RDA_isr(void)
{
int i;

let=getch();
if (let=='$')
{
   letter[0]=getch();
   letter[1]=getch();
   letter[2]=getch();
   letter[3]=getch();
   letter[4]=getch();
   if (letter[0]=='G'&&letter[1]=='P'&&letter[2]=='V'&&letter[3]=='T'&&letter[4]=='G')
   {
   gets(speed);
   
   
   }
     
   if (letter[0]=='G'&&letter[1]=='P'&&letter[2]=='Z'&&letter[3]=='D'&&letter[4]=='A')
   {
   gets(time);
   //for (i=1;i<=6;i++)
   //ck [i-1]=time[i];
   day  [0]=time[12];
   day  [1]=time[13];
   mun [0]=time[15];
   mun [1]=time[16];
   year[0]=time[18];
   year[1]=time[19];
   year[2]=time[20];
   year[3]=time[21];
   }
   if (letter[0]=='G'&&letter[1]=='P'&&letter[2]=='G'&&letter[3]=='G'&&letter[4]=='A')
   {
      gets(letter1);
      //for (i=0;i<=6;i++)
      //ck[i]=letter1[i];       

      for (i=12;i<=22;i++)
         
            L1[i-12]=letter1[i];
           
         
     
      L3=letter1[24];
     
      for (i=26;i<=37;i++)
         L4[i-26]=letter1[i];
     
      L5=letter1[39];
     
     
   
}
}
}

#int_timer0
timer0_isr()
{
   
   set_timer0(255);
   lcd_putc('\f');
   lcd_putc("Hello");
   delay_ms(2000);
}

void main()
{
int i;
      enable_interrupts(GLOBAL);
   enable_interrupts(int_rda);
   enable_interrupts(INT_TIMER0);
   setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
      lcd_init();
   delay_ms(150);
   set_timer0(255);
   
   while(1)
   {
      for (i=0;i<=15;i++)
      lcd_putc(L1[i]);
      puts(L1);
     
     
      delay_ms(1000);
     
      lcd_putc('\f');
      delay_ms(500);
   }
}


This is my test code
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group