 |
 |
| View previous topic :: View next topic |
| Author |
Message |
mka879
Joined: 30 Oct 2015 Posts: 34
|
|
Posted: Wed Nov 04, 2015 6:27 am |
|
|
| ezflyr wrote: | Hi,
Don't fool yourself, delays inside interrupt handlers are a 'significant factor' in virtually *any* circumstance! Just don't do it!
To answer your specific question, the Carriage Return (or Enter key) can be sent with '\r'. |
Thank you, I have modified the code.
Sim900 has a feature of echo back characters which are sent. I can read the characters I sent to the module correctly however when I send AT it does not respond with OK. What might be wrong? The code is as below
| Code: | #include <gsm test.h>
#include<string.h>
#use rs232(baud=9600,xmit=PIN_c6,rcv=PIN_c7,PARITY=N,BITS=8,STOP=1)
char flag[20];
int counter = 0;
#int_rda
void isr_rda(void)
{
if (counter == 0)
output_bit(pin_b4,1);
if (counter == 1)
output_bit(pin_b5,1);
if (counter == 2)
output_bit(pin_b3,1);
if (counter == 3)
output_bit(pin_b2,1);
if (counter == 4)
output_bit(pin_b1,1);
flag[counter] = getc();
clear_interrupt(int_rda);
counter++;
}
void main()
{
//time for GSM Modem to initialize and register on the network
output_bit(pin_b7,1);
delay_ms(1000);
output_bit(pin_b7,0);
delay_ms(1000);
enable_interrupts(global);
enable_interrupts(int_rda);
char par[5] = {'O','K','\r'};
char par1[2];
flag = "no";
while(strcmp(flag,par))
{
delay_ms(4000);
printf("AT\r");
output_bit(pin_b7,1);//flag if sending AT and OK is not received
delay_ms(1000);
output_bit(pin_b7,0);
delay_ms(1000);
}
output_bit(pin_b7,1);//flag if OK is received
} |
When I replace AT\r with AT and check if it is echoed back by sim900 b4 and b5 LEDs become active as indicated by ISR and b7 becomes high indicating AT is received. Whenever AT+enter is sent to the module it responds with OK but if only AT is typed without enter key the module echoes back. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Wed Nov 04, 2015 8:43 am |
|
|
The delays, very much do affect the current situation.
In TeraTerm, typing replies yourself, you take _time_ to reply. The modem does not. It sends it's 'OK', almost instantaneously after receiving the command. _Very_ different.
Last edited by Ttelmah on Thu Nov 05, 2015 2:41 am; edited 1 time in total |
|
 |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Nov 04, 2015 9:51 am |
|
|
Hi,
A couple of things:
1. You need to add the 'Errors' keyword to your #use rs232 directive. This will allow the PIC UART to recover from an overflow without locking up!
2. You can get rid of the 'clear_interrupt(int_rda)' statement inside the ISR. This is already handled by the compiler, and in rare conditions can cause an issue if you do it as well.
There is a complete GSM project in the Code Library provided by forum user 'Gabriel'. I recommend that you study this code to see how he handles the exchange of data between the PIC and the GSM modem. _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
 |
mka879
Joined: 30 Oct 2015 Posts: 34
|
|
Posted: Tue Nov 17, 2015 1:50 am |
|
|
| Thank you everybody especially ezflyr and Ttelmah. ezflyr suggestion of including ERRORS in #use 232 proved to be a life saver. I am so happy after getting the GSM module working correctly. |
|
 |
|
|
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
|