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

Want to get the response from modem

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



Joined: 10 Nov 2008
Posts: 16
Location: Malaysia

View user's profile Send private message Yahoo Messenger

Want to get the response from modem
PostPosted: Wed Mar 11, 2009 1:18 pm     Reply with quote

Hello,

Can everyone take a look to this code. I want to get the response from modem. Like when I send AT, the modem will return "ok". Then send it to hyperterminal.
Code:

#include <18F4620.h>
#include <string.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOLVP, NODEBUG, MCLR
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS,bits=8,stream=GPRS)
#use rs232(BAUD=9600,parity=N,XMIT=PIN_C5,ERRORS,bits=8,stream=PC)

#ifndef NULL
  #define NULL      0
#endif

const int cr=0x0D; // PIC press ENTER


void main()
{
  char buf[25];
  unsigned int8 i;
  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_OFF);
  setup_spi(FALSE);
  setup_wdt(WDT_OFF);
 

  /***start test sequence***/
   while (true)
   {
     delay_ms (1000);
     fprintf(PC,"\r\n***Program started***\n");
     delay_ms (1000);
     fprintf(GPRS,"AT");
     fputc (cr, GPRS);
     delay_ms (1000);
     
     for (i= 0; i <= 25; i++){
     buf[i] = fgetc(GPRS);                   //get the modem respond
     fprintf(PC,"%C",buf[i]);}
     
         
   }

}
Ttelmah
Guest







PostPosted: Wed Mar 11, 2009 3:34 pm     Reply with quote

First, if the modem starts to respond, before one second has passed, the response will at least in part, be lost.
Second, the code will then be stuck in the 'for' loop, till 26 characters are received. If less than this arrive, it'll sit here for ever...

Best Wishes
syide



Joined: 10 Nov 2008
Posts: 16
Location: Malaysia

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Mar 11, 2009 10:40 pm     Reply with quote

Quote:
the code will then be stuck in the 'for' loop, till 26 characters are received


How to solve this problem? is it by using kbhit()?
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE
PostPosted: Thu Mar 12, 2009 12:22 am     Reply with quote

Use the RDA interrupt, this captures whatever comes to the port, getc() will retrieve the data, you probably need to use an array instead of c.
Code:

#int_rda
void modem_cap()
{
  char c;
  c=getc();
}
syide



Joined: 10 Nov 2008
Posts: 16
Location: Malaysia

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 14, 2009 1:35 am     Reply with quote

I still cannot get the response AT with this code.Question

Can someone show the way???


Code:
#include <18F4620.h>
#fuses HS, NOWDT, NOLVP, NODEBUG, MCLR
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS,bits=8,stream=GPRS)
#use rs232(BAUD=9600,parity=N,XMIT=PIN_C5,ERRORS,bits=8,stream=PC)

const int cr=0x0D; // PIC press ENTER

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;
   
      // this blinks a LED :
      static int1 b;
      if (b)
      output_high (PIN_C0);
     
      else
      output_low (PIN_C0);
      b = ! b;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}



void main() {

   char c;
   enable_interrupts(global);
   enable_interrupts(int_rda);

   fprintf(PC,"\r\n\Running...\r\n");

   fprintf(GPRS,"AT");
   fputc (cr, GPRS);
   delay_ms(2000);
   // The program will delay for 10 seconds and then display
   // any data that came in during the 10 second delay
   
   do {
      delay_ms(10000);
      while(bkbhit){
      c=bgetc();

      fputc(c,GPRS);
      fputc(c,PC);
      }
   } while (TRUE);
}
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