ROCKET SCIENTIST
Member level 3
Help!! Give me a subroutine to read the response from a GSM phone through USART.
Hello all,
I'm trying to communicate with my SE k300i phone with an atmega8 running on 8MHz crystal.
I wrote a C code for it which says "AT" from MCU. The phone should say "OK" back to MCU. I want to read this response. Someone told me that the phone response format is" LF CR OK LF CR " SOMETHING LIKE THIS. In this format "CR" is appearing twice.Last one is the string end marker so first one is to be ignored. So, I wrote this code,
the character read function is:
Now the problem is it isn't working!! You may ask for the data send routine
This routine is working. I've tested it by connecting MCU Tx+phone RX and
phone TX+PC RX through max232 and I got "OK" in the terminal...
To show the received data string from phone I used LCD. I wanted to see individual characters received.
codes are:
I know LF and CR are unprintable. But I sdould at least see O and K. why MCU isn't working then? I don't understand. Is the phone response format is wrong???
Please help me guys.:roll:
Thanks in advance,
RS..
Hello all,
I'm trying to communicate with my SE k300i phone with an atmega8 running on 8MHz crystal.
I wrote a C code for it which says "AT" from MCU. The phone should say "OK" back to MCU. I want to read this response. Someone told me that the phone response format is" LF CR OK LF CR " SOMETHING LIKE THIS. In this format "CR" is appearing twice.Last one is the string end marker so first one is to be ignored. So, I wrote this code,
Code:
void read(void) {
int mark=0; i=0;
do {
data[i]=USARTReadChar();
if(data[i]=='\r' && mark==0) mark=1;
if(data[i]=='\r' && mark==1) mark=3;
i++;}
while(data[i-1]!='\r' && mark!=3); }
the character read function is:
Code:
char USARTReadChar() {
//Wait untill a data is available
while(!(UCSRA & (1<<RXC))) {/*Do nothing*/}
/*Now USART has data IN BUFFER*/ return UDR;}
Now the problem is it isn't working!! You may ask for the data send routine
Code:
char at[6]={'A','T','\r','\n','\0'};
void attention(void)
{int j=0;
do {USARTWriteChar(at[j]); j++; }
while(at[j-1]!='\0'); }
This routine is working. I've tested it by connecting MCU Tx+phone RX and
phone TX+PC RX through max232 and I got "OK" in the terminal...
To show the received data string from phone I used LCD. I wanted to see individual characters received.
codes are:
Code:
LCDClear();
for(int dis=0;dis<=5;dis++)
{
LCDGotoXY(0,1);
LCDWriteChar(data[dis]);
_delay_ms(300);
}
_delay_ms(300);
LCDGotoXY(0,1);
LCDWriteChar('\r');
I know LF and CR are unprintable. But I sdould at least see O and K. why MCU isn't working then? I don't understand. Is the phone response format is wrong???
Please help me guys.:roll:
Thanks in advance,
RS..