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 with timer0 and 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 with timer0 and rda interrupt
PostPosted: Tue Apr 10, 2012 7:21 pm     Reply with quote

Hi everybody Smile
My problem is RDA0 interrupt don't work when using with timer0 interrupt.
The MCU which I used is Pic 18f97J60 has 2 UART(UART0 and UART2), 4 timer (0->3).
I used timer0 to check status of button to send SMS alarm, and used RDA0 interrupt to check status of GPRS connection.
I tested with my code, when I press button, SMS alarm is sent, but when I send string to connect with GPRS network, it not run to RDA0 interrupt to check string.
Can I change priority of interrupts by used command (#priority ) in CCS C complier ?
If not, please help me to solve this problem ?
Thanks and regards.
My code:

-- timer0 interrupt (button alarm)

Code:

#int_timer0
void button_rb(void)
{
      if( rb1==0)
            {
             fputs("ATD0905******;\n",ID1); 
             delay_ms(5000);
             fputs("AT+CMGS=\"0905******\"");       
             delay_ms(200);
             fputs("Wellcome goto GPS Tracking Vehicle",ID1);
             delay_ms(100);
             fputc(26);
            }
     
                       
}


-- setup timer0 in main function


Code:

setup_timer_0 ( RTCC_INTERNAL);
set_timer0(0);
enable_interrupts(int_timer0);


-- RDA0 interrupt function

Code:

#int_rda
void ngat_gprs(void)
{
   //disable_interrupts(INT_timer0);
   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;
   }
   
   if((connect_buffer[0]=='C')&&(connect_buffer[1]=='L')&&(connect_buffer[2]=='O')
   &&(connect_buffer[3]=='S')&&(connect_buffer[4]=='E')&&(connect_buffer[5]=='D'))
   {
      chk_closed=1;
      indexx=0;
   }
}



-- setup rs232 port
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=ID1) //GPRS_PORT
#use rs232(baud=4800, xmit=PIN_G1, rcv=PIN_G2,stream=ID2) //GPS_PORT

_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Tue Apr 10, 2012 9:03 pm     Reply with quote

There's a lot wrong with the code. You don't provide enough of it to fully debug though, so can't help much:

1. Add ERRORS to your #use rs232() statements. The serial ports can fail if you do not.

2. You are delaying and sending serial data from within your timer isr. Don't do that.

3. You forgot the stream identifier in some of your fputc calls

Put together a small program that is complete and compilable so we have more to work with. We don't need all of your code, just enough to show the problem while still being able to compile completely. It also helps to know which compiler revision you are using. This is all mentioned in the forum guidelines. Please take a look at those.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Apr 12, 2012 9:03 pm     Reply with quote

jeremiah wrote:
There's a lot wrong with the code. You don't provide enough of it to fully debug though, so can't help much:

1. Add ERRORS to your #use rs232() statements. The serial ports can fail if you do not.

2. You are delaying and sending serial data from within your timer isr. Don't do that.

3. You forgot the stream identifier in some of your fputc calls

Put together a small program that is complete and compilable so we have more to work with. We don't need all of your code, just enough to show the problem while still being able to compile completely. It also helps to know which compiler revision you are using. This is all mentioned in the forum guidelines. Please take a look at those.

Thanks jeremiah ! Smile
I fixed code as you told : (I used PCWH complier ver 4.078)
-- add ERRORS in rs232 declaration but it warnings : variables never used : rs232_errors. Have you used this variable in main program to check errors ?
-- add stream id in fputc() command.
And my code request must used sending serial data from within timer isr, lead to I used delay and rs232 functions to send data, because i used timer0 interrupt to scan button and sending data after that.
Whereby differ I still sending data to rs232 through timer0 interrupt, such as : I'll use label and route it into main program to send data, ex
Code:

#int_timer0
void check_button(void)
{
           var=xxxx;
           goto button;
}

void main (void)
{
           ......
           ......
           run_button:
           fprintf();
           delay_ms();
           fprintf();
           delay_ms();
}


I think so is :D but I don't know its true :D
Please show me a way to solve that, thanks Jeremiah Smile
_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Thu Apr 12, 2012 9:16 pm     Reply with quote

You shouldn't jump out of an ISR like that. If you don't let the compiler do the return from interrupt instruction, then you can really mess things up long term.

Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=ID1,ERRORS) //GPRS_PORT
#use rs232(baud=4800, xmit=PIN_G1, rcv=PIN_G2,stream=ID2,ERRORS) //GPS_PORT


Code:

int1 g_button_hit = 0;
#int_timer0
void check_button(void){
   if(rb1) {
      g_button_hit = 1;
   }
}

void main (void)
{

   rs232_errors = 0;  //Don't really need this, but it gets rid of the warning
           ......
           ......
   while(TRUE){
      sleep();  //only add this if you want to sleep inbetween
      if(g_button_hit){
         //Put your print statements / AT commands here
         g_button_hit = 0;  //assuming you want to use the button multiple times
      }
   }
}


For the serial port data, go to the folder your CCS compiler is installed in and look in the "examples" folder for ex_sisr.c to get an example of how to use the interrupt to read serial data and store it to a buffer which you can then check in the main at your leisure.

Also, you may want more debouncing than the example I gave, unless you have a debounce circuit done in hardware.


Last edited by jeremiah on Fri Apr 13, 2012 6:08 am; edited 1 time in total
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Apr 12, 2012 10:20 pm     Reply with quote

Thanks Jeremiah so much !
I'll retest my code and report my result.
Thanks+regards !
_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Fri Apr 13, 2012 6:32 am     Reply with quote

I edited the code to include a closing bracket that I forgot. Out of curiosity, how fast does the timer0 interrupt trigger?
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Apr 13, 2012 10:24 pm     Reply with quote

jeremiah wrote:
I edited the code to include a closing bracket that I forgot. Out of curiosity, how fast does the timer0 interrupt trigger?

Thanks so much jeremiah !
I fixed code correct.
Ah, and time interval of timer0 interrupt I calculated about 40,96 us, and it so fast ? :D
Have an errors or not optimal in here ? Smile
Thanks and regards !!!
_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Sat Apr 14, 2012 6:33 am     Reply with quote

That might be a bit too fast honestly for monitoring a button press. You might consider slowing it down so your program doesn't spend so much time jumping into ISR code every 41us. People tend to push buttons slower. I would look at something in the low milliseconds range. Up to you though.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Apr 14, 2012 10:47 pm     Reply with quote

jeremiah wrote:
That might be a bit too fast honestly for monitoring a button press. You might consider slowing it down so your program doesn't spend so much time jumping into ISR code every 41us. People tend to push buttons slower. I would look at something in the low milliseconds range. Up to you though.

Thanks jeremiah Smile
and added request in my project is using MMC/SD card to save data from GPS sensor.
You can show me a way to begin to work with it ?
I'm using CCS PCWH to code, and Pic 18F97J60.
Thank you very much!
_________________
Begin Begin Begin !!!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Sun Apr 15, 2012 6:43 am     Reply with quote

I don't know much about SD cards. You could do some forum searches (remember to click "all terms") for:
data logger
SD card
MMC

There are plenty of threads for it here.
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