+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 2
    Points: 199, Level: 2

    Join Date
    Nov 2013
    Posts
    21
    Helped
    4 / 4
    Points
    199
    Level
    2

    Pic18F4550 & SIM300 problem in reading response

    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 alexan_e; 30th November 2013 at 07:40. Reason: added CODE tags

    •   Alt29th November 2013, 10:44

      advertising

        
       

  2. #2
    Advanced Member level 2
    Points: 4,215, Level: 15
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    659
    Helped
    108 / 108
    Points
    4,215
    Level
    15

    Re: Pic18F4550 & SIM300 problem in reading response

    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 by paulfjujo; 29th November 2013 at 11:37.


    1 members found this post helpful.

    •   Alt29th November 2013, 11:25

      advertising

        
       

  3. #3
    Junior Member level 2
    Points: 199, Level: 2

    Join Date
    Nov 2013
    Posts
    21
    Helped
    4 / 4
    Points
    199
    Level
    2

    Re: Pic18F4550 & SIM300 problem in reading response

    thanks lot for ur suggestion...let me check program with changes u suggested......



    •   Alt30th November 2013, 06:22

      advertising

        
       

  4. #4
    Junior Member level 2
    Points: 199, Level: 2

    Join Date
    Nov 2013
    Posts
    21
    Helped
    4 / 4
    Points
    199
    Level
    2

    Re: Pic18F4550 & SIM300 problem in reading response

    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...



  5. #5
    Banned
    Points: 23,048, Level: 36

    Join Date
    Dec 2012
    Location
    Bangalore, India
    Posts
    4,325
    Helped
    802 / 802
    Points
    23,048
    Level
    36

    Re: Pic18F4550 & SIM300 problem in reading response

    Working project attached.




  6. #6
    Junior Member level 2
    Points: 199, Level: 2

    Join Date
    Nov 2013
    Posts
    21
    Helped
    4 / 4
    Points
    199
    Level
    2

    Re: Pic18F4550 & SIM300 problem in reading response

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



+ Post New Thread
Please login