|
|
View previous topic :: View next topic |
Author |
Message |
huihuang1992
Joined: 12 Feb 2016 Posts: 9
|
PIC16F628A with SIM900A GSM |
Posted: Fri Feb 12, 2016 10:21 am |
|
|
Hi, I'm working on this pic and sim900a, and I have some questions.
I want to send a number to SIM900A, so it will receive and give me back with a call, so I use #int_rda to do it.
Code: | #INT_RDA
void RDA()
{
WHILE(TRUE)
{
if(kbhit()==1)
{
movil=getch();
if(movil==1)
{ printf("ATD0034618354363;\r\n");
}
}}}
|
Something is wrong here, and I don't know how to do it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Fri Feb 12, 2016 11:59 am |
|
|
INT_RDA, says _one_ character has been received. Just one.
The whole point about using interrupts, is to allow your main code to carry on doing other things, and yet handle the event signified by the interrupt.
Look at ex_sisr. This shows how to buffer incoming characters using INT_RDA.
General 'rule' is that the interrupt handler, should just 'handle' the event signified by the interrupt. Nothing else. So for INT_RDA, receive just one character, and exit.
INT_RDA says a character is ready to be read. So kbhit is not wanted/needed. However you then loop forever in the interrupt, so will never exit.
Then you are testing for the binary character 1 being received. This is not the text character '1'.
So several things causing problems.... |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri Feb 12, 2016 1:08 pm |
|
|
It seems like you are trying to execute the call from within the ISR.
That is not going to work. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
huihuang1992
Joined: 12 Feb 2016 Posts: 9
|
|
Posted: Tue Feb 23, 2016 5:19 am |
|
|
I try to use INT_RDA to wake up from sleep, and it doesn't work.
I have read that INT_RDA works in SLAVE MODE, and it need a external clock, where should I put this clock? and how to configure it to slave mode?
I have read manys things about this, but still can't solve this.
The datasheet of PIC16F628A says
Quote: | Synchronous Slave mode differs from the Master mode
in the fact that the shift clock is supplied externally at
the RB2/TX/CK pin (instead of being supplied internally
in Master mode). This allows the device to transfer or
receive data while in Sleep mode. Slave mode is
entered by clearing bit CSRC (TXSTA<7>). |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Feb 23, 2016 5:58 am |
|
|
from your post...
the shift clock is supplied externally at
the RB2/TX/CK pin (instead of being supplied internally
in Master mode).
... so you supply the clock signal on RB2.
This will come from a 'master' device,usually another PIC. I serioulsy doubt the SIM900 has such a clock though I haven't read the datasheet and usually it's on a 'module' NOT just the chip.
However in your Original Post is sounds like your project is to'sleep' then when the SIM900 gets a msg, it will reply to you. If so, the SIM900 should have an interrupt output pin to 'wake up' the PIC say on INT_EX0 ? From a philosophy viewpoint, I don't see any need to put the PIC into 'sleep' mode. You should have eitehr line powered supply or a BIG battery for your project as the SIM900 needs a lot of power, far greater than the PIC.
Now several people have posted their working code in the code library and whie not for the 628, would give you knowledge on how they got it to work. The 628 is a 'small' PIC, limited memory but will work fine for this simple application.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Tue Feb 23, 2016 6:11 am |
|
|
You need to read the whole sheet section, not just parts, and look at what each relates to.
The peripheral, is a USART. This stands for Universal Synchronous/Asynchronous Receiver/Transmitter.
It can be programmed to be used as a synchronous device, or an asynchronous device, depending what it is connected 'to'. The modem you are using is asynchronous, so you need to be working in asynchronous mode, and reading the data sheet sections for asynchronous operation.
You are looking at a section for synchronous operation. Not applicable....
The same applies to trying to wake from sleep:
"Asynchronous mode is stopped during Sleep."
Your modem is asynchronous, so you can't use the UART to wake from sleep. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Feb 23, 2016 7:20 am |
|
|
One _possible_ way to wakeup from sleep using the SIM900 serial out to PIC is to also tie it to RB0 and configure the interrupt for the proper edge. Now in the ISR you'd have to be 'clever' to see only the firstedge of the data stream but.... in theory it should be possible.
I haven't tried it on the 628, don't have a SIM900A so I can't test it but it 'sounds good' in my brain.
Jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Feb 23, 2016 7:34 am |
|
|
Hi,
Personally, I'm not interested in helping you anymore with this project. You've got two threads going on this topic, and you've not answered the several questions that were asked of you in the other thread. If you expect continued help with your project, don't waste our time by asking for help and then ignoring the efforts being made to help you!! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Feb 23, 2016 7:51 am |
|
|
I don't mind 'lending a hand',heck I'd even cut code if he supplied me the hardware(GSM, sim card, etc). It's too cold here to go out and play and sifting though 30 year old databooks is mind numbing as to what I used to do!
Anyone wirewrap anymore? Found my UV eraser and a tube of 16C71s !!
Jay |
|
|
huihuang1992
Joined: 12 Feb 2016 Posts: 9
|
|
Posted: Tue Feb 23, 2016 7:57 am |
|
|
Thank you guys for reply.
Here is my code, please ignore comments >
Code: | #include <16f628a.h>
#include <string.h>
#fuses NOWDT //Watch dog timer no esta activado desde principio
#fuses NOPROTECT,NOPUT,XT
#fuses MCLR,NOBROWNOUT,IESO
//#fuses INTRC_IO // Internal RC Osc, no CLKOUT
#use delay(clock=4M) // Ojo a INTERNAL, determina la duracion
#use RS232(BAUD=9600,bits=8,parity=N, XMIT=PIN_B2, RCV=PIN_B1,stop=1,ERRORS)
#include <tones.c>
#byte TRISB=0x86 //indicar si es entrada o salida
#byte PORTB=0x06 //indica si esta en nivel alto o bajo
int1 vibracion=0;
int16 contadorT0=0;
int16 contadorVIB=0; //int8=>256 cuentas, cuando contadorVIB llega 10<x<30, sigue contando, entonces llegara 256 algun momento, y vuelve a contar desde 0.
#DEFINE dato_size 80
char dato[dato_size];
int a=0;
int x=0;
int c=0;
#int_ext //Interrupcion a la pata numero 6, RB0/INT, usaremos el INT para la interrupcion externa, ya que es de salida ST
void RB0(){
contadorVIB++;}
#int_RB
void RB4(){
enable_interrupts(INT_EXT);
}
#INT_RDA //esta interrupcion despertara el PIC y hara una busqueda de ubicacion y enviar la ubicacion por SMS al numero de movil correspondiente
void RDA_isr()
{if (kbhit())
{c=getc();
dato[x]=c;
x++;
}
}
void borrar_arrany(){
for (a=0;a<dato_size;a++)
{
dato[a]=0;
}
a=0;
x=0;
c=0;
}
#int_timer0
Void timer0(){
SET_TIMER0(246);
contadorT0++;
//output_toggle(PIN_A3);
if (contadorT0==625) // 158X5.06ms == 799.48ms( este valor aun tendremos que cambiar segun la situacion
// he comprobado con una carga de 1000, el cual tiene que entrar en la interrupcion despues de dejar el pulsador de reset 5 segundos.
{
if((contadorVIB>10) && (contadorVIB<30))//hay que discutir en los valores
{
vibracion=1;
}
else
{
vibracion=0;
}
contadorVIB=0;
contadorT0=0;//resetea el contador
}
}
void main(){
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128 );//usamos un reloj interno, division 2
setup_timer_1(T1_EXTERNAL | T1_CLK_OUT | T1_DIV_BY_1 );
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
SET_TIMER0(246);
TRISB=0b00110011;//declara que RB0 sea entrada, las otras de RB sea salida
PORTB=0x00;
borrar_arrany();
enable_interrupts
enable_interrupts(INT_RDA);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RB);
enable_interrupts(INT_EXT_H2L); // turn on external interrupt H->L
enable_interrupts(GLOBAL);
printf("ATE0\r\n");
delay_ms(500);
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(1000);
printf("ATA\r\n"); //Coger la llamada
delay_ms(200);
printf("ATH\r\n"); //colgar la llamada
delay_ms(200);
printf("AT+CGATT=1\r\n");
delay_ms(200);
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(2000);
printf("AT+SAPBR=2,1\r\n"); //obtencion de IP direccion
delay_ms(500);
borrar_arrany();
//delay no afecta
printf("AT+CIPGSMLOC=1,1\r\n");
delay_ms(3000);
printf("AT+CMGF=1\r\n"); // Seleccionor modo texto
delay_ms(500);
printf("AT+CMGS=\"0034618354363\"\r\n"); //enviar el mensaje a mi numero
delay_ms(500);
printf("Http://maps.google.com/maps?z=12&t=m&q=loc:%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(5000);
borrar_arrany();
}
if ((input(PIN_B4)==1) && (vibracion==1) ){
generate_tone(1000,3000);
delay_ms(2000);
disable_interrupts(INT_EXT);
sleep();
}
if (input(PIN_B4)==0){ //si no hay luz, no genera nada
output_low(PIN_A1);
delay_ms(100);
disable_interrupts(INT_EXT);
sleep();
}
}
} //cierra void main
|
Let me explain a little how it works:
The idea is I give a call to SIM900A, then it will answer me with a sms which has the information about the actual location.
And I want to do wake it up when the PIC16F628A is sleeping, cause I'm using 2xbat 3.7V, SIM900A will get 5V because I have a 7805, and both of them(PIC and SIM900A) will be sleeping when it's necessary.
INT_EXT(RB0) and INT_RB(RB4) is busy now, because I have other things conected. RB will wake up the PIC, too.
SIM900A has RX,TX,RST,GDN and Vcc, those conexions.
So, I'm answering if it's possible to wake up the PIC with INT_RDA, and maybe change some hardware to make it possible. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Tue Feb 23, 2016 8:13 am |
|
|
Not really.
To use INT_RDA, the modem would have to develop asynchronous data. It doesn't.
You could possibly 'logically wire OR' the modem data and whatever currently uses INT_RB0, with diodes or an external gate, so that when either signal goes to it's active state the interrupt is received, but problem here is that the chip will take a significant time to wake up (crystal takes time to start as well), so you would really need a 'dummy' character, then a pause to wake the chip, while GSM, is really a packet based format not supporting this.
A lot more 'basic' thought is needed.... |
|
|
huihuang1992
Joined: 12 Feb 2016 Posts: 9
|
|
Posted: Tue Feb 23, 2016 8:18 am |
|
|
ezflyr wrote: |
Personally, I'm not interested in helping you anymore with this project. You've got two threads going on this topic, and you've not answered the several questions that were asked of you in the other thread. If you expect continued help with your project, don't waste our time by asking for help and then ignoring the efforts being made to help you!! |
I'm so sorry I haven't see the last replies in other lines :( I have just seen now, I'm going to reply to it now. I was concentrated to how to resolve the problems. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Feb 23, 2016 8:18 am |
|
|
please post a 'link' to the GSM module you are using so I can get the dataspecs on it.
Jay |
|
|
huihuang1992
Joined: 12 Feb 2016 Posts: 9
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Tue Feb 23, 2016 9:58 am |
|
|
I only looked at the first few lines, and there are so many little faults, that it is no wonder things don't do what you want. Get one thing working at a time...
First, in INT_RB, you _must_ read at least one bit of portB. This is in the data sheet, and has been explained here. The act of reading the port, is what sets the internal latch to match what is currently on the port. Until this happens, the interrupt cannot be cleared, and INT_RB will trigger forever, stopping the code from ever actually exiting the interrupt. Disaster...
Then INT_RDA, says 'a character has been received'. Testing kbhit is pointless...
Then you do not check that 'x' has not exceeded the size of the array. If data arrives that is not exactly what you want, this will result in memory becoming corrupted. Again disaster.
Then you have a line 'enable_interrupts', without a interrupt for it to enable. Doubt if this will compile.
Then you send a huge sequence of commands to the modem. Every one of these will receive a reply from the modem (OK probably). You do nothing to empty the data buffer, so by the time you start looking for 'RING', the buffer will have a huge number of characters already in it. Result 'RING' won't be where you expect it.
I gave up at this point.... |
|
|
|
|
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
|