0
char rcv[10];
void main()
{

UART1_Init(9600);
Delay_ms(2000);
TRISB=0x00;

UART1_Write_Text("at");
UART1_Write(13); //Enter key = CF + LF
UART1_Write(10);
delay_ms(500);

while (1)
{ PORTB.RB0=1; // Endless loop
while(!UART1_Data_Ready()); // If data is received,
rcv[0]=UART1_Read();
rcv[1]=UART1_Read();
rcv[2]='\0';
UART1_Write_Text(rcv);
PORTB.RB0=0;
}
}

Compiler used : MikroC I get the rcv output as ATTTTTTTTT. Pls help me out here to receive OK response from GSM Modem as this works with Hyperterminal. Using PIC 18F4520 in PICPLC16v6 development board from Mikroelectronika.

KB29
  • 1
  • 1

1 Answers1

0

It seems that you have the modem echo set on, so you'll receive each caracter you send it.

I would rewrite your code to something like :

void main(void)
{
  uint8_t cmd[10];
  uint8_t answer[20];
  uint16_t timeout = 500; //max miliseconds to wait for an answer
  UART1_Init(9600);
  Delay_ms(1000);
  TRISB=0;  
  cmd[0]='A';
  cmd[1]='T';
  cmd[2]=13;
  cmd[3]=10;
  cmd[4]=0;//marks end of CMD string
  while(1)
  {
     uint8_t answer_len = SendModemCMD(cmd,answer,timeout);
     UART1_Write_Text(answer);
     Delay_ms(500);//not really needed ...
  }
}

uint8_t SendModemCMD(uint8_t *cmd,uint8_t* answer,uint16_t timeout)
{
  uint16_t local_timeout;
  uint8_t answer_len=0;
  while(*cmd!=0) 
  {
    UART1_Write(*cmd++);
    local_timeout=timeout;
    while(local_timeout>0 && !UART1_Data_Ready())
    {
      Delay_ms(1);
      local_timeout--;
     }
    if(UART1_Data_Ready())
    {
      UART1_Read();//discard echoed character
    }
  }
  uint8_t finished=0;
  while(finished==0) 
  {
    local_timeout=timeout;
    while(local_timeout>0 && !UART1_Data_Ready())
    {
      Delay_ms(1);
      local_timeout--;
     }
    if(UART1_Data_Ready())
    {
      *answer++=UART1_Read();
      answer_len++;
    }
     else
    {
      finished=1;
    }
  }
  *answer=0;
  return answer_len;   
}