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 support@ccsinfo.com

Interrupt problem with PIC16F628 interfaced with GM862-PCS..

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



Joined: 16 Dec 2005
Posts: 22

View user's profile Send private message

Interrupt problem with PIC16F628 interfaced with GM862-PCS..
PostPosted: Sun Mar 23, 2008 10:48 pm     Reply with quote

Hi Everybody!

I wanted to interface GM862-PCS with PIC16F628 through RS232. The program that I researched and made seemed to work perfectly during my simulation with Proteus through Virtual serial ports. But when I did the project in actual, I am having a problem getting the data from the GSM module that I am using now. After several tries and researching, I'm no longer sure if I did miss something. Here's the simplest code that I made after several revisions:

Compiler Version: 4.038
Proteus Version: 7.1 sp6


Code:
#include <16F628A.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1)

#define LOAD1 PIN_B5
#define LOAD2 PIN_B6
#define LOAD3 PIN_B7
#define PILOTOK PIN_B3
#define PILOTERROR PIN_B4
#define BUFFER_SIZE 50
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

short load1stat = FALSE;
short load2stat = FALSE;
short load3stat = FALSE;

#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=0;           //Cyclic Buffer --> wraps up overwriting the data
}

void init_gsm() {

   printf("AT\r");
   delay_ms(100);

   printf("AT+IPR=9600\r");
   delay_ms(100);

   printf("AT+CMEE=2\r");
   delay_ms(100);

   printf("AT#WAKE=0\r");
   delay_ms(100);
   

}

void set_sms() {

   printf("AT+CMGF=1\r");
   delay_ms(200);

   //printf("AT+CNMI=2,1\r");      // I have the choice to let the GSM
   //delay_ms(200);                    // module to notify the PIC if message
}                                              // is received before I read it.

void delete_all() {
   printf("AT+CMGD=1,4\r");
   delay_ms(1000);
}

void read_message() {   // This will read the message recieved
   printf("AT+CMGR=1\r\n");
   delay_ms(500);
}

void clean_buffer() {
   int x;
   
   for(x=0;x<BUFFER_SIZE;x++) buffer[x] = '\0';
}

void indicate_ok() {
   output_high(PILOTOK);
   output_low(PILOTERROR);
}

void indicate_error() {
   output_low(PILOTOK);
   output_high(PILOTERROR);
}

void main() {
   char on1[4];
   char on2[4];
   char on3[4];
   char off1[5];
   char off2[5];
   char off3[5];
   char garbage;
   short message_recieved = FALSE;
   
   delay_ms(1000);
   
   strcpy(on1,"on1");
   strcpy(on2,"on2");
   strcpy(on3,"on3");
   strcpy(off1,"off1");
   strcpy(off2,"off2");
   strcpy(off3,"off3");
   
   output_high(PILOTERROR);
   
   delay_ms(12000);  // Long wait for the GSM module to initialize
   
   indicate_ok();
   delay_ms(100);
   indicate_error();
   
   init_gsm();
   delay_ms(900);
   
   indicate_ok();
   delay_ms(100);
   indicate_error();
   
   set_sms();
   delay_ms(900);   
   
   indicate_ok();
   delay_ms(100);
   indicate_error();
   
   delete_all();
   delay_ms(2000);
   
   indicate_ok();

   indicate_ok();
   
   if(kbhit()) {
      while(kbhit()) {
         garbage = getc();
      } 
   }
   
   enable_interrupts(global);
   enable_interrupts(int_rda);

   do {
           
      indicate_ok();
     
      read_message();   // I just choose to try read for received msg at
                                  // location SM and index 1
      delay_ms(10000);
      indicate_error();
     
      if(strstr(buffer,on1)) {
         if(!load1stat) {
            load1stat = TRUE;
            output_high(LOAD1);
         }
      }
      else if(strstr(buffer,on2)) {
         if(!load2stat) {
            load2stat = TRUE;   
            output_high(LOAD2);
         }
      }
      else if(strstr(buffer,on3)) {
         if(!load3stat) {
            load3stat = TRUE;
            output_high(LOAD3);
         }
      }
      else if(strstr(buffer,off1)) {
         if(load1stat) {
            load1stat = FALSE;
            output_low(LOAD1);
         }
      }
      else if(strstr(buffer,off2)) {
         if(load2stat) {
            load2stat = FALSE;
            output_low(LOAD2);
         }
      }
      else if(strstr(buffer,off3)) {
         if(load3stat) {
            load3stat = FALSE;
            output_low(LOAD3);
         }
      }
     
      indicate_ok();
      delay_ms(300);
      indicate_error();
     
      delete_all();
     
      next_in = 0;
      clean_buffer();
     
   } while (TRUE);
}


Somebody help me find the fault of the program I made. Thank you very much. The schematic?

just GM682 PIC16F628
RX -------------------> TX
TX -------------------> RX
GND

"If I'll use the PC/Hyperterminal to act as the GSM Module, the program works perfectly"

"Don't want to use hardware flowcontrol"

Laughing

Any help will be highly appreciated! THank you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 23, 2008 11:50 pm     Reply with quote

Quote:
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

Add the ERRORS directive as shown in bold. If the GM862 device starts
sending data before you enable RDA interrupts, it could lock up the
UART receiver. With the ERRORS directive, this won't happen.
Do this in all your programs that use the hardware UART.
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