Pic18F4550 & SIM300 problem in reading response

Status
Not open for further replies.

KVN1477

Junior Member level 3
Joined
Nov 18, 2013
Messages
26
Helped
4
Reputation
8
Reaction score
4
Trophy points
3
Activity points
184
Hi all..
i am trying to establish the communication between PIC18F4550 & SIM 300 GSM modem. the following code is tested on protuse it is working. i have even tested modem & PIC circuit on PC hyper terminal every thing is working properly. but when i connect PIC with Simcom SIM 300 module pic is NOT reading OK response from SIM 300 module when I send AT & AT+CMGF=1.
i did every connection properly. i.e Txof PIC to RX of MOdem ...&.... Rx of PIC to Tx of Modem. GND to GND (PIN NO.4&6 and PIN NO.7& 8 of modem are shorted) ......Plz help me

Code:
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


char gsm_response[20];

void gsm_send_command(char *command)
{
  while(*command)
   { 
     uart1_write(*command++);
   }

      uart1_write(13);
      uart1_write(10);
}
void gsm_read_line(char *buffer)
 {  
    char uart_rd;
   do
    {                    // Endless loop
      if(UART1_Data_Ready()){
      uart_rd = UART1_Read();     // read the received data,
      *buffer++=uart_rd; }
      
    }  while (uart_rd != '\r\n');
  }
void main()
  {  
  
    ADCON1 = 0x0F;
   
    CMCON=0;                            // comparator off
    UART1_Init(9600);               // Initialize UART module at 9600 bps
    Delay_ms(200);                  // Wait for UART module to stabilize
    Lcd_Init();                        // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR);               // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
       
    gsm_send_command("AT");
   
    gsm_read_line(gsm_response);
  if(memcmp("OK",gsm_response,2)!=0)
  {  
     lcd_cmd(_lcd_clear);
     lcd_out(1,1,"Error AT...");
     while(1);
   }
  Lcd_cmd(_Lcd_clear);
  Lcd_out(1,1,"FINE1");
  lcd_OUT(2,1,GSM_RESPONSE);
  gsm_send_command("AT+CMGF=1");
  
  gsm_read_line(gsm_response);
 
 if(memcmp("OK",gsm_response,2)!=0)
  {
     lcd_cmd(_lcd_clear);
     lcd_out(1,1,"Error TEXT");
     while(1);
   }
   Lcd_cmd(_Lcd_clear);
   Lcd_out(1,1,"FINE2");
   lcd_OUT(2,1,GSM_RESPONSE);
 }
 
Last edited by a moderator:

hello

while (uart_rd != '\r\n');

you can not compare 2 cars with One
choose \r or \n

or test booth

while( (*( buffer-1)!='\r') && (*(buffer)!="\n"));
and add a zero at end of the string
*(buffer+1)=0;


i didn't where is the init of your buffer
RAM allocation
and init of this pointer..

For handling string, it's better also to initiate
example:
char texte[40]; // define maxi size !
char * buffer; // pointer
buffer=texte; // value of the pointer
*(buffer)=0; // means empty string
 
Last edited:
thanks lot for ur suggestion...let me check program with changes u suggested......
 

as per ur suggestion i made following changes it is working fine in protuse but not working on pic.
Code:
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


char gsm_response[20];

void gsm_send_command(char *command)
{
while(*command)
{
uart1_write(*command++);
}

uart1_write(13);
uart1_write(10);
}
void gsm_read_line(char *buffer)
{
char uart_rd;
do
{ // Endless loop
if(UART1_Data_Ready()){
uart_rd = UART1_Read(); // read the received data,
*buffer++=uart_rd; }

} while (*(buffer-1)!='\n');
*(buffer+1)=0;
}
void main()
{

ADCON1 = 0x0F;

CMCON=0; // comparator off
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(200); // Wait for UART module to stabilize
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

gsm_send_command("AT");

gsm_read_line(gsm_response);
if(memcmp("OK",gsm_response,2)!=0)
{
lcd_cmd(_lcd_clear);
lcd_out(1,1,"Error AT...");
while(1);
}
Lcd_cmd(_Lcd_clear);
Lcd_out(1,1,"FINE1");
lcd_OUT(2,1,GSM_RESPONSE);
gsm_send_command("AT+CMGF=1");

gsm_read_line(gsm_response);

if(memcmp("OK",gsm_response,2)!=0)
{
lcd_cmd(_lcd_clear);
lcd_out(1,1,"Error TEXT");
while(1);
}
Lcd_cmd(_Lcd_clear);
Lcd_out(1,1,"FINE2");
lcd_OUT(2,1,GSM_RESPONSE);
}
plz help me...
 

Thanks a lot jayanth.devarayanadurga......i never imagined such a grate response...
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…