Controller not able to collect response from GSM Modem

Hello all,

I am trying to send Command from 89S52 Controller to SIM900 GSM Modem

when i am sending command as

"AT" in response my Receive buffer is able to receive all bytes and code is working fine.

if request is "AT"Response is "AT 0X0D 0X0A 0X0D 0X0A OK " -> working fine

but if i send command as “AT+IPR=9600”

then expected response should be same "AT 0X0D 0X0A 0X0D 0X0A OK " but my buffer is not able to collect it.

it is receiving "AT " and after this it is receiving junk characters (in second attempt i tried to make buffer memory dynamically allocated but that is making program more dirty)

GSM is responding correctly (i verified it using hyperterminal), my code is not able to receive it correctly.

/*drivers.c*/


extern int buf_count;
char Rec_buf[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

void serial_IT(void) interrupt 4
{
 if (RI == 1)
 {
         /* if reception occur */
   RI = 0; /* clear reception flag for next reception */
   Rec_buf[buf_count] = SBUF; /* Read receive data */

         buf_count++;
         if(buf_count == 10)
         {
                buf_count = 0;
   }
 }

}



void Send_cmd(char *cmd)
{
  while(*cmd != '\0')
  {
   Uart_send(*cmd);
         cmd++;
  }

  Uart_send(0x0D);
  Uart_send(0X0A);

}

void Uart_send(char data_snd)
{
        TI = 0;
        SBUF = data_snd;
        while(TI==0);
        TI = 0;
}



/*application.c*/

int Check_rsponse_OK(void)
{
                int ret_val = 0;
          if(Rec_buf[0] == 'A' && Rec_buf[1] == 'T' && Rec_buf[2] == 0x0D && Rec_buf[3] == 0X0A && Rec_buf[4] == 0x0D && Rec_buf[5] == 0x0A &&  Rec_buf[6] == 'O' && Rec_buf[7] == 'K')
                {
                                port_0_0 = 1;
                                port_0_1 = 0;
                          ret_val = 1;
                }
                else
                {
                                port_0_0 = 0;
                                port_0_1 = 1;
                          ret_val = 0;
                }
                return ret_val;
}


/*main.c*/

void main (void)
{

 int ret_val = 0;

 init_app( );

 Send_cmd(Check_cmd);

do
 {
        ret_val = Check_rsponse_OK();
 }while(ret_val != 1);

 Reset_receiver_Buffer();
 while(1);

}

Parents
  • Your assumptions are wrong, and you have a too small receive buffer.

    You see an AT and a OK as response because you have echo on.

    But echo on means that when you send the command "AT+IPR=9600" you will not just get an AT+OK back. You will first get the echo of the sent command (including cr+lf) then you will get an OK + cr+lf as response to the command.

    So 10 characters of receive buffer is way too small, making the OK overwrite the start of the command echo.

    It helps to experiment with the Hyperterminal or similar and look at exactly how the modem behaves.

Reply
  • Your assumptions are wrong, and you have a too small receive buffer.

    You see an AT and a OK as response because you have echo on.

    But echo on means that when you send the command "AT+IPR=9600" you will not just get an AT+OK back. You will first get the echo of the sent command (including cr+lf) then you will get an OK + cr+lf as response to the command.

    So 10 characters of receive buffer is way too small, making the OK overwrite the start of the command echo.

    It helps to experiment with the Hyperterminal or similar and look at exactly how the modem behaves.

Children
More questions in this forum