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

Communication between SIM900A and 16F628A

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



Joined: 12 Feb 2016
Posts: 9

View user's profile Send private message

Communication between SIM900A and 16F628A
PostPosted: Wed Feb 17, 2016 1:08 pm     Reply with quote

Hello,
What I try to do is call from my mobile to SIM900A, and it answers with a message location. But I see that the characters are not correct, and I have tried many times and can not find the solution.
Code:

#include <16f628a.h>
#include <string.h>


#fuses NOWDT   //Watch dog timer no esta activado desde principio

#fuses NOPROTECT,NOPUT,HS
#fuses MCLR,NOBROWNOUT


#use delay(clock=20M)     // Ojo a INTERNAL, determina la duracion
#use RS232(BAUD=9600,bits=8,parity=N, XMIT=PIN_B2, RCV=PIN_B1,stop=1)   
//#include <tones.c>

#byte TRISB=0x86 //indicar si es entrada o salida
#byte PORTB=0x06  //indica si esta en nivel alto o bajo



#DEFINE dato_size 80
char dato[dato_size];
int a=0;
int x=0;
int c=0;


#INT_RDA      //esta interrupcion despertara el PIC y hara una busqueda de ubicacion y enviar la ubicacion por SMS al numero de movil correspondiente
RDA_isr()
{if (kbhit())
 {c=getc();
  dato[x++]=c;
 
 }return 0;
 clear_interrupt(int_rda);
}     
     
void borrar_arrany()
{
for (a=0;a<dato_size;a++)
{
dato[a]=0;

}
a=0;
x=0;
c=0;
}
 
 }
void main(){ 
//setup_oscillator( OSC_48kHZ ); //esta determina la frecuencia
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2 );//usamos un reloj interno, division 2
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
  SET_TIMER0(236);//CARGA 220 =>0.012s

TRISB=0b00110011;//declara que RB0 sea entrada, las otras de RB sea salida
PORTB=0x00;
borrar_arrany();
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
printf("ATE0\r\n");
delay_ms(100);
borrar_arrany();

while(true){

if(dato[2]== 'R' &&dato[3]== 'I' &&dato[4]=='N' &&dato[5]=='G') //Detecta si hay el mensaje dice RING

delay_ms(500);
printf("ATA\r\n");
delay_ms(300);
printf("ATH\r\n"); //colgar la llamada
delay_ms(300);
borrar_arrany();
   printf("AT\r\n");
     delay_ms(100);
     
       printf("AT+CGATT=1\r\n");
        delay_ms(500);
        borrar_arrany();
       printf("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n");  //Set the connection type to GPRS
        delay_ms(500);
       printf("AT+SAPBR=3,1,\"APN\",\"INTERNET\"\r\n"); //Set the APN to to "internet" since i am using a simyo SIM card, It might be different
       delay_ms(500); 
       borrar_arrany();
       printf("AT+SAPBR=1,1\r\n");
        delay_ms(3000);           
       printf("AT+SAPBR=2,1\r\n");
        delay_ms(1000);
        borrar_arrany();
        delay_ms(1000);//delay no afecta
       printf("AT+CIPGSMLOC=1,1\r\n");
        delay_ms(2500);

         printf("AT+CMGF=1\r\n");     // Seleccionor modo texto
         delay_ms(1000);       
         printf("AT+CMGS=\"0034618354363\"\r\n"); //enviar el mensaje a mi numero
         delay_ms(1000);
         printf("www.google.es/maps?q=%c%c%c%c%c%c%c%c%c",dato[25],dato[26],dato[27],dato[28],dato[29],dato[30],dato[31],dato[32],dato[33]);
         printf("+%c%c%c%c%c%c%c%c\r\n",dato[16],dato[17],dato[18],dato[19],dato[20],dato[21],dato[22],dato[23]);   //el texto del mensaje
         putchar(0x1a);
         delay_ms(10000);
       
       
     }
 

   }
}



And the message to give me is:
Code:
www.google.es/maps?q=CMGS="003+ OK AT


If anyone has an idea, comment it, please!
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Feb 17, 2016 4:50 pm     Reply with quote

Hi,

First of all, please don't start a new topic each time you have a question! Your old topic is here: http://www.ccsinfo.com/forum/viewtopic.php?t=54832 Please use it!

Are you absolutely sure that you are able to receive data from the GSM modem? When you send the 'ATE0' command, you should capture the modems response, which should be 'OK'. Until you can do this, there is no point in trying to proceed any further. My guess is that you've got some sort of a hardware incompatibility that needs to be addressed before you see any success!

A couple of things to consider:

1. This is an English speaking forum. If all your program comments are non-English, you put those that want to help you at a great disadvantage.
2. You should add the 'Errors' directive to the 'USE RS232' statement in your code. This will prevent the hardware UART from locking up if it becomes overrun with incoming data.
3. Add a 'Stream' directive to your 'USE RS232', such as "GSM", so that it's abundantly clear when you are sending/receiving data to the GSM modem.
4. Most GSM modems will add <CR> and/or <LF> to the beginning and end of each data transmission. You can use these extra characters to know when data is beginning and ending.
5. You don't need to 'Clear Interrupts' inside the ISR. The compiler will add that code for you.
6. The PIC 16F628A is woefully inadequate for a serious GSM project. At a minimum, am 18F series device should be used. Most of my GSM designs are based on the 18LF25K50. I chose this device because it operates well at the voltage of my GSM module, so they are powered from the same source, and it has built-in USB for firmware updates!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Feb 17, 2016 8:50 pm     Reply with quote

Hi,

I have posted 2 working codes on the library doing basic sms control.... it should give you some insight to your proyect.
_________________
CCS PCM 5.078 & CCS PCH 5.093
huihuang1992



Joined: 12 Feb 2016
Posts: 9

View user's profile Send private message

PostPosted: Thu Feb 18, 2016 11:48 am     Reply with quote

First at all, thank you ezflyr for the great response.
I'm sure that GSM receive data, because I have tried with AT command and it works great.
The thing is likes the captures of date was not correct.
I will try all these advises and I will answer here.
Thank you.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Feb 18, 2016 2:00 pm     Reply with quote

Hi Huihuang1992,

Your PIC is running at 5v, correct? Your SIM900 is running at 3.8V, or thereabouts, is that also correct? Can you describe the interface between the PIC and the SIM900? Are you connecting the SIM900 Tx pin directly to the PIC Rx pin? Are you connecting the PIC Tx pin directly to the SIM900 Rx pin?

As I said, getting the hardware correct is Step #1!
_________________
John

If it's worth doing, it's worth doing in real hardware!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 18, 2016 2:35 pm     Reply with quote

That PIC should run fine at 3V IF running at 10MHz or LESS.....
It's NOT designed to run at 20 MHz at less than 5 volts though.

What's written on the front page of the datasheet can be misleading so you need to read the datasheet, electrical specs section, easy charts to
look at, be sure to look at the PIC16F62x chart NOT the PIC16LF62x chart
though.

As stated though we really need to see or be told HOW the units are connected. Best case is 3 volt PIC and a 3 volts GSM.
Jay
huihuang1992



Joined: 12 Feb 2016
Posts: 9

View user's profile Send private message

PostPosted: Tue Feb 23, 2016 8:24 am     Reply with quote

ezflyr wrote:
Hi Huihuang1992,

Your PIC is running at 5v, correct? Your SIM900 is running at 3.8V, or thereabouts, is that also correct? Can you describe the interface between the PIC and the SIM900? Are you connecting the SIM900 Tx pin directly to the PIC Rx pin? Are you connecting the PIC Tx pin directly to the SIM900 Rx pin?

As I said, getting the hardware correct is Step #1!


It works now, and I just install another pickit2 programmer.
And I'm connecting PIC with a battery of 3.7v and SIM900A with 2x3.7v, but with a regulator, so it is working with 5V. And it all works correctly. And I'm connecting directly the RX and TX, and it works now.

The doubt I have now is in other thread, which is how to wake up with INT_RDA.
Sorry for responding so late!
Best regards.
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