|
|
View previous topic :: View next topic |
Author |
Message |
vjn86
Joined: 12 Oct 2009 Posts: 11
|
INTERRUPT NOT TRIGGERED DURING INCOMING DATA FROM GSM |
Posted: Sun Mar 21, 2010 6:01 am |
|
|
Hi there. I have tried to understand Gabriel’s read sms function coding so that I can integrate the coding into my final year project. I’m expecting the following to happen :
1. Initially a command sms : *Led1 1* been send to the gsm.
2. When the program runs, it suppose to copy the message into receive_string array.
3. And then the “ while loop” that ignore character until it found * and save the message Led1 1 until it found another *
4. Then the code suppose print the receive string array ( it suppose to show: Led1 1)
But when I execute it didn’t print the array. I have even tried to print the array before the while loop(I was expecting it to show info a gsm modem suppose to show when at+cmgr=1 command is typed in hyperterminal) but it didn’t show it neither. Then I tried to toggle a led in the interrupt function just to check whether the interrupt is triggered when there is incoming serial data during at+cmgr=1 function. But it isn’t triggered. What is the mistake I possible done ?
An interesting point to note is, my printf function are working fine..meaning that when the pic kit and gsm modem are connected through cross rs 232cable, the pic sends at command n getting the response( I knew this because when I unplug the gsm modem from pic kit n connected to my pc’s hyperterminal, immediately all the at response is displayed in hyperterminal ) I have tried 9600 bps and also 115200bps but still no changes
Can anyone help to guide me on this ? I really need to get this function working so that I can move on to next problem in my project.
thanks
with regards
vijay
Code: |
#include <16f877a.h>
#device adc=10
#include <string.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect
#use rs232(baud=9600, bits=8, parity=N, stop=1, xmit=PIN_C6, rcv=PIN_C7, stream=gsm,ERRORS)
#use rs232(baud=9600, bits=8, parity=N, stop=1, xmit=PIN_B0, rcv=PIN_B1, stream=pc,ERRORS)
//#define BUFFER_SIZE 70
CHAR recieve_string[70];
int counter_read ;
//BYTE next_out = 0;
//int NEXT_CMD;
//char CMD_string;
//char b;
/*
#int_rda
void rs232_handler()
{
b=fgetc(gsm);
recieve_string[counter_read+1]=b;
counter_read++;
}
*/
/*
#int_rda
void serial_isr() {
int t;
output_low(PIN_A2);
recieve_string[counter_read]=fgetc(gsm);
t=counter_read;
counter_read++ % BUFFER_SIZE;
if(counter_read==next_out)
counter_read=t;// Buffer full !!
if(counter_read==69)counter_read=0;
}
*/
#INT_RDA
void SerialInt()
{
int counter_read =0;
recieve_string[counter_read]=fgetc(gsm);
counter_read++;
if(counter_read==69)counter_read=0;
output_high(PIN_A2); // TO TEST WHETHER INTERRUPT IS WORKING OR NOT
}
void READ_SMS();
//void GET_CMD();
//void DO_CMD();
void main()
{
fprintf(gsm,"AT\r\n");
delay_ms(1000);
fprintf(gsm,"AT+CMGF=1\r\n");
delay_ms(1000);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
READ_SMS();
//GET_CMD();
//DO_CMD();
DELAY_MS(1000); // TO TOGGLE OFF THE LED THAT THE INTERRUPT TRIGGER ON
output_low(PIN_A2);
}
void READ_SMS()
{
counter_read=0;
fprintf(gsm,"AT+CMGR=1\r\n"); // send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROCESSING
// putchar(0x0D);
delay_ms(2000);
fprintf(pc,"%s",recieve_string); // I TRIED TO OBTAIN ALL THE STRING THAT SUPPOSE TO BE SHOWN WHEN AT +CMGR=1 SHOWS IN HYPERTERMINAL;
while(recieve_string[counter_read]!='*') // ignore everything untill message starts
{
}
counter_read=0; // start saving message at the begining of the array
while(recieve_string[counter_read]!='*') // get the message
{
}
counter_read=0;
delay_ms(1000);
fprintf(pc,"%s",recieve_string); // I TRIED TO GET PIC TO PRINT LED1 1
delay_ms(1000);
}
/*
void GET_CMD()
{
const char CMD1[]={"Led1 0"};
const char CMD2[]={"Led1 1"};
delay_ms(1000);
NEXT_CMD=0xff;
strcpy (CMD_string, CMD1);
if(strncmp(recieve_string,CMD_string,6))
NEXT_CMD=0;
strcpy (CMD_string, CMD2);
if(strncmp(recieve_string,CMD_string,6))
NEXT_CMD=1;
}
Void DO_CMD()
{
if(NEXT_CMD==0)output_high(PIN_B1);
if(NEXT_CMD==1)output_high(PIN_B3);
}
*/
|
|
|
|
vjn86
Joined: 12 Oct 2009 Posts: 11
|
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Mar 22, 2010 3:05 am |
|
|
Edit:-
Forget what I just wrote below, I got confused because you have a GLOBAL var called counter_read and a LOCAL var (in your int) called counter_read. I have made a similar mistake in the past and CCS does not like it, it does not tell you you have done it either.
Change one of them, actuall what you are doing doesn't make much sense so just fix it the way you meant it to work.
(you are incrementing counter_read after you receive a char but each time you reset it to 0)
Your problem may be this.
Code: |
while(recieve_string[counter_read]!='*') // ignore everything untill message starts
{
}
|
When a char is received you store it at counter_read and then increment counter_read before exiting the interrupt routine.
This loop above always checks the character at counter_read which will always be the position AFTER the char you just receieved.
LOL, just looked and there is another problem
Code: |
#INT_RDA
void SerialInt()
{
int counter_read =0;
|
Your int routine sets counter_read to 0 everytime.
You proberbly meant to set this as static ?
Or initialise it out side the interrupt, before it is enabled.
Actually just need to check something, another edit is on it's way |
|
|
vjn86
Joined: 12 Oct 2009 Posts: 11
|
|
Posted: Mon Mar 22, 2010 4:32 am |
|
|
hi wayne ...u have ask me to forget some reply that u worte below..which one is it ? |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Mar 22, 2010 5:14 am |
|
|
LOL, sorry about that, I left the info in because I thought it may be of use to you but basically I sent the reply and then realised it wasn't quite correct so I altered it and then I realised that you had the duplicate variable as global and a local so I changed it again.
Your problem is most likely the fact you have a global called counter_read which I believe you intended to use in your interrupt routine as well BUT you have created a local in your interrupt routine with the same name.
Now, I had a similar problem but my global and local var had different types, The global was 8 bit and the local 16. CCS was compiling OK but the routine with the local var referenced the global one.
But as I stated in the rest of the post there are a few things you need to sort out. But they may be fixed depending on how you correct the first problem. |
|
|
vjn86
Joined: 12 Oct 2009 Posts: 11
|
|
Posted: Sun Mar 28, 2010 1:58 pm |
|
|
Hi wayne...
I got it working now. Millions thanks to u .. Just for your info, it also didn't work because i didn't short pin 7 n 8 in my RS232 cross cable and i didn't use the proper way to print an array using for function... Anyway thank you very much...
with regard
Vijay |
|
|
|
|
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
|