|
|
View previous topic :: View next topic |
Author |
Message |
ninebarmaximus
Joined: 27 Feb 2006 Posts: 20
|
reading gsm on rs232 |
Posted: Tue Apr 18, 2006 10:59 am |
|
|
i hope someone can help me with my problem im sure what im trying to do is not difficult, maybe im just going the wrong way about it.
I have a gsm sim card connected to my 16f74 and i know that it is able to see the information from the gsm sim since i can see it on the oscilloscope but i am having trouble reading the information.
The following is essentially the code that i am using,, could someone please tell me if i am making any fundamental errors or if what im doing is just plain wrong!!
thanks for the help
Code: |
#include <16F74.h>
#device adc=8
#fuses NOWDT,XT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=3645000)
#use rs232(baud=9600, parity=n, bits=8, xmit=pin_a2, rcv=pin_a4,ERRORS, stream=PC)//PC
#use rs232(baud=9780, parity=n, bits=8, xmit=pin_c6, rcv=pin_c7, stream=GSM)//GSM
int timeout;
char answer;
long testtimer;
char responce[14];
int counter;
int i;
void main()
{
start:
timeout=0;
testtimer=0;
while ((!kbhit(PC)&&(++timeout<500))) // 5ms
{
delay_us(10);
}
if(kbhit(PC))
{
if (answer=='r')
{
output_high(PIN_B1);//puts rst in high state
timeout=0;
while ((!kbhit(GSM)&&(timeout<254)))
{ timeout=timeout+1;
fprintf(PC," T=");
fprintf(PC,"%U",timeout);
delay_us(10);
}
if(kbhit(GSM))
{
counter =0;
timeout=0;
if(kbhit(GSM))
{
responce[1]=getch(GSM);
counter++;
}
if(kbhit(GSM))
{
responce[2]=getch(GSM);
fprintf(PC,"|two responce written |");
counter++;
}
if(kbhit(GSM))
{
responce[3]=getch(GSM);
fprintf(PC,"|three responce written |");
counter++;
}
if(kbhit(GSM))
{
responce[4]=getch(GSM);
fprintf(PC,"|four responce written |");
counter++;
}
if(kbhit(GSM))
{
responce[5]=getch(GSM);
fprintf(PC,"|five responce written |");
counter++;
}
if(kbhit(GSM))
{
responce[6]=getch(GSM);
fprintf(PC,"|six responce written |");
counter++;
}
fprintf(PC," H=");
for (i=0;i<=counter;i++)
{
fprintf(PC,"%X",responce[i]);
fprintf(PC," ");
}
fprintf(PC," gotostart in kbhit GSM|");
output_low(PIN_B1);
goto start;
}
}
else
{
fprintf(PC," no kbhit GSM |");
output_low(PIN_B1);
goto start;
}
}
else
{
fprintf(PC,"NO");
goto start;
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 18, 2006 2:35 pm |
|
|
I would get rid of all the getch() statements with the timeouts for
the GSM stream. I would put in a interrupt-driven receive buffer,
as shown in the CCS example file EX_SISR.C.
Then you just sit in a loop and call bkbhit() to see if there's a character
available in the buffer. If there is, then call get bgetc() to fetch the
char and put it into your "responce" array. Increment the array index
after you put each character into it. Check the index against the size
of the array to make sure you don't overrun the end of the array.
When the index reaches the desired value, then display the array.
Because you're using streams, you will need to modify the serial_isr()
routine in EX_SISR.C to use fgetc(GSM) instead of getc() as they do in
the example. |
|
|
ninebarmaximus
Joined: 27 Feb 2006 Posts: 20
|
|
Posted: Wed Apr 19, 2006 5:23 am |
|
|
thank you very much for your responce and i will try to implement the changes now |
|
|
ninebarmaximus
Joined: 27 Feb 2006 Posts: 20
|
|
Posted: Wed Apr 19, 2006 7:12 am |
|
|
thank you very much PCM programmer you are a complete legend. that example you mentioned when modified slightly, works an absolute treat.
cheers again |
|
|
ninebarmaximus
Joined: 27 Feb 2006 Posts: 20
|
odd occurences in stream? |
Posted: Wed Apr 19, 2006 11:53 am |
|
|
i have implemented the example in EX_SIRI.C to get information from an expernal device using interrupts, its just that i have it set up so when the line b1 goes high i should reveive an answer to reset. Which it does. at least it looks ok, but then if i press 'r' again, (the line b1 is already high so it stays high) i get the same 4 characters each time i do it after the initial reset, are these 4 characters stuck in the buffer until i try and read it again or are they just some errors that i should ignore?
when i do the command once i get
3B3F94008069AF030706680075(hex)
and when i press it again i get the extra characters
0A0E
the code im using is as follows
Code: |
#include <16F74.h>
#device adc=8
#fuses NOWDT,XT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=3645000)
#use rs232(baud=9600, parity=n, bits=8, xmit=pin_a2, rcv=pin_a4,ERRORS, stream=PC)//PC
#use rs232(baud=9600, parity=n, bits=8, xmit=pin_c6, rcv=pin_c7,ERRORS, stream=GSM)//GSM
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in=0;
BYTE next_out=0;
#define bkbhit (next_in!=next_out)
long timeout;
char answer;
long testtimer;
#int_rda
void serial_isr()
{
int t;
buffer[next_in]=getc(GSM);
t=next_in;
next_in=(next_in+1)%BUFFER_SIZE;
if (next_in==next_out)
next_in=t; //buffer full!!
}
BYTE bgetc()
{
BYTE c;
while (!bkbhit);
c=buffer[next_out];
next_out=(next_out+1)%BUFFER_SIZE;
return(c);
}
void main()
{
enable_interrupts(global);
InitialContacts();
start:
timeout=0;
testtimer=0;
while(!kbhit(PC)&&(++timeout<1000))
delay_us(10);
if(kbhit(PC))
{
answer=getch(PC);
if (answer=='r')
{
enable_interrupts(int_rda);
output_high(PIN_B1);
delay_ms(50);
while (bkbhit)
fprintf(PC,"%X",bgetc());
disable_interrupts(INT_RDA);
goto start;
}
goto start;
}
goto start;
}
|
|
|
|
|
|
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
|