We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi. I am having a little problem. I have my MCB900 evaluation board connected to a gsm modem via serial cable. I have wrote a simple program to send out the "AT" command to the modem from the eval board. I then read back on the serial and store the charters in a buffer and I then compare the buffer and light the LEDs depending on what I get. At the moment I have the code set up that all 8LEDs light if I recieve "AT on the serial but I know it should be reading in "OK" from the GSM module.
Q. Do I have to clear SBUF after I send the message to the GSM modem and before I start to reading back from the GSM modem
/*------------------------------------------------------------------------------ ------------------------------------------------------------------------------*/ #include <REG935.H> #include <stdio.h> #include <string.h> int u=0; int step = 1; char sms[2]; void init(void); /*------------------------------------------------ The main C function. ------------------------------------------------*/ void main() { SCON = 0x52; /* initialize UART */ BRGR0 = 0xF0; /* 9600 baud, 8 bit, no parity, 1 stop bit */ BRGR1 = 0x02; BRGCON = 0x03; ADMODA = 0x30; /* SCAN=1 single conversion */ ADINS = 0xF0; /* Enable AD10..AD13 inputs */ ADMODB = 0x60; /* CLK: 1.5MHz for 12MHz XTAL */ ADCON1 = 0x05; /* Enable+start A/D converter */ while (1) { if(u !=2){ P2 = 0x01; } if(step==1){ init(); } } } void init(void){ if(u !=2){ P2 = 0x03; } if(u < 1){ printf ("AT\n"); /*output AT message to modem*/ } while (RI != 1) {;} /*wait for serial input from modem*/ sms[u] = SBUF; /*store modem message in buffer*/ SBUF=0;/*clear SBUF*/ RI= 0; u++;/*increment next character of message*/ if(u==2){ if(sms[0] == 0X41 && sms[1] == 0X54){ /*comparing if message from modem is "AT" should be "OK"*/ P2 = 0xFF; /*if "AT" light all 8 LED's*/ }else{ P2 = 0x1F; /*else light 5 LED's*/ } step = 1; } }
.
Since the OP doesn't even consider the possibility that it's the modem doing the echoing, I think by far the most likely assumption is that it is the modem that's doing the echo...
Hi all, It was indeed the modem echoing back. Thanks for your help.