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; } }
.
Why do you think "SBUF=0" would clear any SBUF?
Don't you think writing 0 to SBUF would represent sending of the value 0 on the serial port?
How would the processor be able to distinguis between any "clear SBUF" and an attempt to write data to the serial port? By reading the comments in your source code?
What is your conclusion after having read the user manual/datasheet and potentially looked at the available example code?
Thanks for your input.
I still dont understand why the message I am sending out on the serial in been echoed back. The code seems to work on the simulator and also when the evaluation board is connected to the Hyperterminal but when I connect the evalutaion board to the Gsm modem the meesage sent is returned back. it would help if i could see the messages transmitted between them.
Is it correct that SBUF stores only 1 character. So if I send "AT" on the serial port the last character in SBUF would be "T"?
Thank you for you time.
Haven't you ever heard about echo? Never tried to connect a serial port to a "normal" modem, and sent characters to the modem and seen the characters being returned back?
Ever read the manual for the modem and looked at available settings to turn on/off echo?
SBUF can only handle one character at a time. But SBUF is not a memory cell. So there is no "last character stored". SBUF is a gateway for forwarding data from your program into the UART. The same moment you send a character into SBUF, you no longer knows anything about where that character is. By definition.
But you have a status flag you can check, to verify when SBUF, the gateway or portal, is ready to forward a new character into the UART.
And SBUF is a dual-direction gateway/portal. So writing to SBUF means data going from program into UART. Reading means picking up data received from the UART.
But if you see SBUF as a gateway or portal - then think about this: Does the door to your apartment/house "store" people? Does the door of a car "store" people? So if two people gets into the car, would the last person then be stored in the doorway?
SBUF is two registers a Transmit and a Receive. The TX is write only and the Receive is read only. if you Write 'A' then 'T' the Tx buffer is empty when the TX is complete.
Assuming the GSM is not setup to echo back, then you have a short or other HW issue.
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.