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 sending command from 16F877 to GPRS modem

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



Joined: 08 Jun 2011
Posts: 2

View user's profile Send private message

Problem sending command from 16F877 to GPRS modem
PostPosted: Wed Jun 08, 2011 8:21 pm     Reply with quote

Hi guys, first post here Smile

I'm trying to communicate my 16F877 with a GPRS modem (ADH8066 with the evaluation board from sparkfun).

I'm using the following code:

Code:

#include <16F877A.h>

#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,NOBROWNOUT,NOWRT

#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GPRS,ERRORS)

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

#define bkbhit (next_in!=next_out)
char cmd_str[20];

byte bgetc()
{
   byte c;

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

#int_rda
void serial_received()
{
   int t;

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

void init()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   output_high(GSM_ONKEY);
   output_high(GSM_CTS);
   output_high(GSM_DSR);
   output_low(GSM_LED);
}


int startGSM()
{
   delay_ms(200);
   output_high(GSM_ONKEY);
   output_high(GSM_CTS);
   output_high(GSM_DSR);
   delay_ms(500);
   output_low(GSM_ONKEY);
   delay_ms(2000);
   output_high(GSM_ONKEY);
   delay_ms(300);
   output_low(GSM_CTS);
   output_low(GSM_DSR);
   delay_ms(4000);

   //ler ready!

   return 1;
}

void testePrintGSM()
{
   delay_ms(1000);
   fprintf(GPRS,"AT\n");
   delay_ms(1000);
}


void main()
{
   int8 cont = 0;
   
   unsigned char a;

   init();
   
   timeout(5);
   
   output_high(GSM_LED);
   
   startGSM();
   
   output_low(GSM_LED);

   timeout(15);

   while(true)
   {
      // Searches for 'ady' from the word Ready witch means modem has reset
      if (bkbhit)
      {
      a = bgetc();
      }
      if (a == 'a')
      {
         a = bgetc();
         if (a == 'd')
         {
         a = bgetc();
            if (a == 'y')
            {
            output_high(GSM_LED);
           
            timeout(3);
           
            testePrintGSM();
            }
         }
      }
     
      // Searches for OK, reply from the command fprintf(GRPS,"AT\n")
      else if (a == 'O')
      {
         a = bgetc();
         if (a == 'K')
         {
          output_low(GSM_LED);
         }
      }
     
      delay_ms(50);
   }



Sorry for the big code, anyways, I'm able to read from the modem the "Ready" reply, but I can't read the OK reply, so I assume I'm not being able to send the "AT\n" command. Any ideas?


BTW I've already tried fprintf, putc, and so on, with no luck :/

Thanks,

WildLife
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 08, 2011 9:13 pm     Reply with quote

Quote:
fprintf(GPRS,"AT\n");

Your final character is a newline, but the modem expects a carriage
return, which is a \r.
WildLife



Joined: 08 Jun 2011
Posts: 2

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 8:59 am     Reply with quote

PCM programmer wrote:
Quote:
fprintf(GPRS,"AT\n");

Your final character is a newline, but the modem expects a carriage
return, which is a \r.


That might have saved me some hassle in the future, but still it isn't working :(

Any other thoughts?

Thanks
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