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

Get GSM response using interrupts

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



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

Get GSM response using interrupts
PostPosted: Fri Aug 31, 2012 9:26 am     Reply with quote

Hello guys, I want to ask something. I hope you all can help. I want to display "OK" from gsm modem to lcd. This is my coding. Can someone help me ? I can't get the response.

GSM modem: SIMCOM
Code:

#include <16f876a.h>
#device adc=8
#use delay (clock=20000000)
#fuses hs,nolvp,nowdt,noprotect,nobrownout
#use rs232(baud=9600, bits=8, xmit=pin_C6, rcv=pin_C7, parity=n, stream=GSM)
#byte porta=5
#byte portb=6
#byte portc=7
#include "flex_lcd.c"
#include <string.h>

int GET_OK(Stop_Search);
int TEST_AT();
volatile int  counter_search=0;            //counter to traverse the array
volatile int  counter_read=0;             //counter to fill the array
volatile Char Recieve_String[70];   //buffer for incoming data

#INT_RDA
void SerialInt()
{
   Recieve_String[counter_read]=getchar();
   counter_read++;
   if(counter_read==69)counter_read=0;
}

void main()
{
SET_TRIS_A( 0x00 ); 
SET_TRIS_B( 0x00 );
OUTPUT_B(0X00);
SET_TRIS_C( 0x00 );

enable_interrupts(INT_RDA);  // enable RDA interrupts
enable_interrupts(GLOBAL);   // enable global ints

lcd_init();
lcd_putc("\fget OK");
output_high(PIN_C4);    //led on
delay_ms(500);
output_low(PIN_C4);    //led off
delay_ms(500);
output_high(PIN_C4);
delay_ms(500);
output_low(PIN_C4);
delay_ms(1000);

while(1)

if(TEST_AT())
{
lcd_putc("\fComplete");
}
}
}

int TEST_AT()
{
   counter_read=0;

   printf("AT\n\r");                //send command

   output_high(PIN_C4);
   while(counter_read<=8)         
   {
   }
   output_low(PIN_C4);

   counter_read=0;
   delay_ms(500);               

   if(GET_OK(0X0A))
      return(1);
   else return(0);
}

int GET_OK(Stop_Search)
{
   counter_search=0;

   while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))   //check buffer until an 'O' is found or 10 chars have been checked.
   {
      counter_search++;     //obvious
   }

   if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))  //check for a 'K' after the 'O'
   {
      counter_search=0;
      return(1);              //function returns true
   }
   return(0);
   counter_search=0;
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Sep 03, 2012 9:08 am     Reply with quote

Hi,

You need to test your LDC individually to rule out display hardware problems.

Then, you need to test your connections between PIC and CELL.

Remember that in rs232 comm, there is a DTE and DCE.

Both PIC and CELL are DCEs... so you need to swap TX/RX lines.


Remove the TRIS settings... I did that in the past to "save power" ... its not necessary at this moment in your project.

THE MOST IMPORTANT PART HERE IS:

Code:

int TEST_AT()
{
   counter_read=0;

   printf("AT\n\r");                //send command

   output_high(PIN_C4);
   while(counter_read<=8)  //<------------------THIS PART       
   {
   }
   output_low(PIN_C4);

   counter_read=0;
   delay_ms(500);               

   if(GET_OK(0X0A))
      return(1);
   else return(0);
}


If your modem does not respond to the "AT" command with more than 8 chars you will be stuck inside that loop.

Try this better (my code was specific to my modem):
Code:

int TEST_AT()
{
   counter_read=0;

   printf("AT\n\r");                //send command

   output_high(PIN_C4);
   delay_ms(500);             //<------------------CHANGE TO THIS
   output_low(PIN_C4);

   counter_read=0;
   delay_ms(500);               

   if(GET_OK(0X0A))
      return(1);
   else return(0);
}


I hope that helps.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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