[SOLVED]simcom sim900d problem(i can not write any AT Command)

Status
Not open for further replies.

zula

Full Member level 2
Hi i have sim900d development board. When i tried to configure it via hyperterminal or putty(hyperterminal program) i failed. I connect it properly i think. Because hyperterminal sensing the com8. But when i tried to write any AT Command it is invisible. How can i fix this.

regards.

Last edited:

zula

Full Member level 2
iam sure for that.

ves

ves

Points: 2

Primark

Newbie level 6
just make sure that you haven't issued this command ATE0&W, my sim900d malfunctions every now and then I issue ATE0, anyways if ever you have, then there is a work around, during boot-up of the gsm there is at least 3 seconds to type this command ATE1, then wait for a response, OK should appear if you manage to do it correctly, then you can issue ATE1&W, this method worked for me, hope it works for you

ckshivaram

When you type AT nothing is coming or some funny characters come.....

I think you have baud rate problem... check the cable by doing loop back test to confirm cable and port are working fine.......

Primark

Newbie level 6
actually the baudrate is not an issue especially in hyperterminal, so long as the gsm is set at AT+IPR=0, there will be no problem at all, anyways, does anybody here know why sim900d screws up everytime ATE0 is issued, my gsm sure does, I have to reset the gsm for it to function again.

ckshivaram

Other than this command doe it work for all other commands.

How can you communicate when IPR=0.. baud rate mismatch is the reason.... make it AT+IPR=9600 and try,.....

what is the default baud rate of your GSM? check that .. other wise evertime your GSM will get screwed

Primark

Newbie level 6
sir, actually it is possible to sync sim900d with hyperterminal just by inputting "A" at the window.
I have a question though.
This code works perfectly with sim340
void commitGSMSendMessage(char eventMessage[]){
initUSART();
delay(8000000);
sendUART_rom(gsmSendSMSMessage);
putcUSART(0x22);//"
sendUART_rom(gsmSendSMSNumber);
putcUSART(0x22);//"
sendUART_rom(gsmSendSMSSpacing);
delay(50000);
putsUSART(eventMessage);
//sendUART_rom(gsmSendSMSContent);
putcUSART(0x1A);//control z
delay(8000000);
CloseUSART();
}

but it doesn't work with sim900d, any suggestions

---------- Post added at 09:46 ---------- Previous post was at 09:43 ----------

And about using the AT+IPR=0, I'm pretty certain sir that it can be sync via hyperterminal by issuing "A"

ckshivaram

cant tell anything from this need complete code to find the problem

Primark

Newbie level 6
ah ok I'll send a code

#include <usart.h>
#include <p18f4550.h>

#pragma config FOSC = HSPLL_HS //HS oscillator, PLL enabled, HS used by USB
#pragma config PLLDIV = 2 //this is used to get 4Mhz out of a 8Mhz xtal and multiply it to 96Mhz
#pragma config WDT = OFF //disable watch dog timer
#pragma config LVP = OFF //disable low voltage programming
//note: at 96Mhz 1000000 delay is equal to 2.35s in the real world...
//rom memory for constants
const rom char gsmAT[] = "AT";
const rom char gsmTxtMode[] = "AT+CMGF=1;&W"; //set gsm to text mode then save
const rom char gsmIsinTxtMode[] = "AT+CMGF?";
const rom char gsmBaudRate[] = "AT+IPR?";
const rom char gsmEchoOff[] = "ATE0";
const rom char gsmReadMessage[] = "AT+CMGR=1";
const rom char gsmDeleteMessage[] = "AT+CMGD=1";
const rom char gsmDeleteInboxMessages[] = "AT+CMGDA=\"DEL INBOX\"";
const rom char gsmSendSMSMessage[] = "AT+CMGS=";
const rom char gsmSendSMSNumber[] = "+639088893767";
const rom char gsmSendSMSSpacing[] = "\r\n";
const rom char gsmSendSMSContent[] = "test";
const rom char gsmSetBaudRate[] = "AT+IPR=57600;&W"; //set gsm to baudrate to 57600 then save
//data memory
#define bufferLength 20
unsigned char bufferCtr=0, x=0, y=0;
unsigned short long z = 0;
char gsmCMDResponseBufferForATEBD[bufferLength];//buffer for response of at, txt mode, echo off, baud rate and Delete; feeds either OK or +CMS ERROR: <number>
char gsmResponse[6];
char retries = 0;
char gsmSendSMSMessageBuffer[8];
char gsmSendSMSNumberBuffer[15];
char gsmSendSMSSpacingBuffer[2];
char gsmSendSMSContentBuffer[6];

//prototype
void initBuffer(void);
void sendATtoGSM(void);
void str2ram(static char *, static char rom *);
void setGSMtoTextMode(void);
void setGSMEchoOff(void);
void delay(unsigned long);
void commitGSMDeleteMessage(void);
void commitGSMDeleteInboxMessages(void);
void commitGSMSendMessage(void);
void setGSMInitConfig(void);
void checkGSMBaudRate(void);
void trialAT(void);
void initUSART(void);
void turnOnOrOffGSM(void);
void customGSMResponse(static char *, unsigned char);
void setGSMBaudRate(void);
void sendUART_rom( static const rom char *);
unsigned char responseExpected(char[], char[], unsigned char, unsigned char);
void gsmSetSystemDebugMode(void);
void gsmSetSystemNormalMode(void);
void warningGSMinPDUMode(void);
void commitInterpretMessage(void);
//prototype upto here

void main(){
ADCON1 = 0x0F; //adcon controls all AN port, it can set it to either digital or analog; set (AN0:AN12) to digital input
CMCON = 0x07; //configure PORTA comparators as digital input
TRISA = 0; //set port A to output
PORTA = 0;
TRISE = 0x2; //set PORT E0 to output, PORTE1 to input;
PORTE = 0;
PORTA = 0b00001111;//this is because bit7 is unimplemented that is why only 7 bits are mentioned here
delay(1000000);//supposively this is 2 seconds
PORTA = 0;
TRISD = 0;
PORTD = 0;
PORTDbits.RD1 = PORTEbits.RE1;
delay(1000000);
if(PORTEbits.RE1 == 1){//this will cause the gsm to reset intentionally
turnOnOrOffGSM();
}
PORTDbits.RD1 = PORTEbits.RE1;
delay(1000000);
while(PORTEbits.RE1 != 1){//this block will keep the gsm on
turnOnOrOffGSM();
}
PORTAbits.RA0 = 1;
delay(5000000);//wait for 10 seconds before using gsm
if(PORTEbits.RE1 == 0) //for some reason the block above fails to keep the gsm on
turnOnOrOffGSM();
checkIfGSMisReady();//we will validate the gsm first...
PORTAbits.RA1 = 1;
initBuffer();//if above initialization fails, this will still initialize the buffer
setGSMInitConfig();
PORTAbits.RA2 = 1;
PORTAbits.RA3 = 1;
//commitGSMDeleteMessage();
//commitInterpretMessage();

//commitGSMSendMessage();
commitGSMDeleteInboxMessages();
PORTA = 0;
while(1);
}
void sendUART_rom(static const rom char *data){
do{
while(BusyUSART())
;
putcUSART(*data);
}while(*data++!='\0');//condition to continue to the last pointer address however do not include null
}
void initBuffer(){
for(bufferCtr=0; bufferCtr<6; bufferCtr++)
gsmCMDResponseBufferForATEBD[bufferCtr] = ' ';
}

x = 1;
while(x){
initUSART();
delay(100000);
trialAT();
for(y=0; y<6; y++){
z=100000;
while(!DataRdyUSART() && z!=0)
z--;
if(!DataRdyUSART())
gsmResponse[y] = '*';
else
gsmResponse[y] = getcUSART();
}
if(gsmResponse[2] == 'O' && gsmResponse[3] == 'K')
x=0;
delay(50000);
retries++;
PORTA = retries%16;
if(retries%16==0){//this is a fail safe feature just in case the gsm does not respond properly it will force the gsm to restart
turnOnOrOffGSM();
}
CloseUSART();
}
}
void checkIfGSMisInTextMode(){//this will inquire about the current status of the GSM
initBuffer();
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmIsinTxtMode);//check if now gsm is in text mode
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
while(!('1'==gsmCMDResponseBufferForATEBD[9])){
setGSMtoTextMode();
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmIsinTxtMode);//check if now gsm is in text mode
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
delay(1000000);
}
initBuffer();
}
void checkGSMBaudRate(){//this will inquire about the current status of the GSM
initBuffer();
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmBaudRate);//inquire first if gsm is in text mode
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
while(!('5'==gsmCMDResponseBufferForATEBD[8] && '7'==gsmCMDResponseBufferForATEBD[9] && '6'==gsmCMDResponseBufferForATEBD[10]
&& '0'==gsmCMDResponseBufferForATEBD[11] && '0'==gsmCMDResponseBufferForATEBD[12])){
setGSMBaudRate();
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmBaudRate);//check if now gsm is in text mode
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
delay(1000000);
}
initBuffer();
}
void setGSMtoTextMode(){
initBuffer();
while(!('O'==gsmCMDResponseBufferForATEBD[2] && 'K'==gsmCMDResponseBufferForATEBD[3])){
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmTxtMode);
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
delay(1000000);
}
initBuffer();
}
void setGSMBaudRate(){
while(!('O'==gsmCMDResponseBufferForATEBD[2] && 'K'==gsmCMDResponseBufferForATEBD[3])){
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmSetBaudRate);
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmTxtModeResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
delay(1000000);
}
initBuffer();
}

void setGSMEchoOff(){
while(!('O'==gsmCMDResponseBufferForATEBD[2] && 'K'==gsmCMDResponseBufferForATEBD[3])){
initUSART();
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
sendUART_rom(gsmEchoOff);
putcUSART(0x0D);//carriage return "\r"
//getsUSART(gsmEchoOffResponseBuffer, 6);
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
delay(1000000);
}
initBuffer();
}

void delay(unsigned long ctr){
while(ctr!=0)
ctr--;
}

initUSART();
delay(500000);//delay for a second before reading data
putcUSART(0xA);//new line;
putcUSART(0x0D);//carriage return "\r"
CloseUSART();
delay(50000);
}
void commitGSMDeleteMessage(){
initBuffer();
while(!('O'==gsmCMDResponseBufferForATEBD[2] && 'K'==gsmCMDResponseBufferForATEBD[3])){
initUSART();
delay(50000);
putcUSART(0xA);//new line;
sendUART_rom(gsmDeleteMessage);
putcUSART(0x0D);//carriage return "\r"
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
CloseUSART();
}
delay(50000);
}
void commitGSMDeleteInboxMessages(){
initBuffer();
initUSART();
delay(50000);
putcUSART(0xA);//new line;
sendUART_rom(gsmDeleteInboxMessages);
putcUSART(0x0D);//carriage return "\r"
customGSMResponse(gsmCMDResponseBufferForATEBD, bufferLength);
delay(4000000);//wait for the gsm to completely delete all messages before closing usart
CloseUSART();
delay(50000);
}
void setGSMInitConfig(){//write initial settings of gsm
checkGSMBaudRate();
checkIfGSMisInTextMode();//checking and setting done in a single fashion
}
void str2ram(static char *dest, static char rom *src){
while ((*dest++ = *src++) != '\0')
;
}
void commitGSMSendMessage(){
initUSART();
delay(8000000);//allow gsm to breathe
putcUSART(0xA);//new line
putcUSART(0x0D);//carriage return
str2ram(gsmSendSMSMessageBuffer, gsmSendSMSMessage);
putsUSART(gsmSendSMSMessageBuffer);//send message command
putcUSART(0x22);//"
str2ram(gsmSendSMSNumberBuffer, gsmSendSMSNumber);
putsUSART(gsmSendSMSNumberBuffer);//number
putcUSART(0x22);//"
str2ram(gsmSendSMSSpacingBuffer, gsmSendSMSSpacing);
putsUSART(gsmSendSMSSpacingBuffer);//number
delay(50000);
str2ram(gsmSendSMSContentBuffer, gsmSendSMSContent);
putsUSART(gsmSendSMSContentBuffer);//content
putcUSART(0x1A);//control z : 0x1A in hex, 26 in deci
delay(8000000);//allow gsm to breathe
CloseUSART();
}
void trialAT(){
putcUSART(0xA);//new line;
sendUART_rom(gsmEchoOff);
putcUSART(0x0D);//carriage return "\r"
CloseUSART();
delay(100000);
initUSART();
sendUART_rom(gsmAT);
putcUSART(0x0D);//carriage return "\r"
}
void initUSART(){
OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX & //FOSC 48000000
USART_BRGH_HIGH, 51); //baud rate is equal to SPGRGH SETTING found at page 251 of data sheet//51 is equal to 57600
//fOSC/(16 * (val + 1)) at high speed
//fOSC/(64 * (val + 1)) at low speed
// OpenUSART(USART_TX_INT_OFF &
// USART_RX_INT_ON &
// USART_ASYNCH_MODE &
// USART_EIGHT_BIT &
// USART_CONT_RX &
// USART_BRGH_LOW, 77); //since our FOSC acutally is 48Mhz not just 8Mhz due to PLLDiv and our desired baud rate is 9600
}
void turnOnOrOffGSM(){
PORTEbits.RE0 = 1;//one long press
delay(2500000); //approx 5s
PORTEbits.RE0 = 0;
delay(8000000);//approx 16s
}

void customGSMResponse(static char *destination, unsigned char len){
char messageBuffer[100];
char *messagePointer;
unsigned char messageFlag = 1;
for(y=0; y<len; y++){
z=500000;
while(!DataRdyUSART() && z!=0){
z--;
if(z==0){
messageBuffer[y] = '*';
break;
}
}
if(z!=0)
messageBuffer[y] = getcUSART();
}
messagePointer = 0;
messagePointer = &messageBuffer[0];
while((*destination++ = *messagePointer++) != '\0');
}
unsigned char responseExpected(char expectedResponse[], char GSMResponse[], unsigned char expectedLen, unsigned char responseLen){
//from here on we verify two things, we veriry both length filtered message and content
unsigned char isCorrect = 1;
unsigned char ctr=0;
char messageBuffer[100];//It seems as though it doesn't matter if its 100 or 6 since it doesn't seem to affect the data memory
for(y=0; y<responseLen; y++)//this block will count the number of characters in the response
if(GSMResponse[y] == 0xA || GSMResponse[y] == 0xD || GSMResponse[y] == ' ')
ctr++;
if(expectedLen != (responseLen - ctr))
isCorrect = 0;
if(isCorrect == 1){
for(y=0; y<responseLen; y++)//this block will extract the message for easy comparison
if(GSMResponse[y] == 0xA || GSMResponse[y] == 0xD || GSMResponse[y] == ' ')
;
else{
messageBuffer[x] = GSMResponse[y];
x++;
}
for(y=0; y<expectedLen; y++)//this block will compare the extracted message to the expected message
if(messageBuffer[y] != expectedResponse[y])
isCorrect = 0;
}
return isCorrect;
}
void commitInterpretMessage(){//this block will check for the message either ^0000^ for normal mode and ^0001^ for debug mode and for future options
y = -1;
for(x=0; x<100; x++)//this block will track the locatio of the first ^
y = x;
break;
}
if(y!=-1){//first z has been found
gsmReadMessageResponseBuffer[y + 3] == '0' && gsmReadMessageResponseBuffer[y + 4] == '0' && gsmReadMessageResponseBuffer[y + 5] == 'z')
gsmSetSystemNormalMode();
else if(gsmReadMessageResponseBuffer[y] == 'z' && gsmReadMessageResponseBuffer[y + 1] == '0' && gsmReadMessageResponseBuffer[y + 2] == '0' &&
gsmReadMessageResponseBuffer[y + 3] == '0' && gsmReadMessageResponseBuffer[y + 4] == '1' && gsmReadMessageResponseBuffer[y + 5] == 'z')
gsmSetSystemDebugMode();
}
else
warningGSMinPDUMode();
}
void gsmSetSystemDebugMode(){
for(x=0; x<16; x++){
PORTA = x%16;
delay(500000);
}

}
void gsmSetSystemNormalMode(){
for(x=0; x<16; x++){
PORTA = x%8;
delay(500000);
}
}
void warningGSMinPDUMode(){
for(x=0; x<16; x++){
PORTA = x%4;
delay(500000);
}
}

andrei.tarziu

Newbie level 2
same problem

Hello,

I have the same problem over here with sim900D EVB. I studied the datasheet and i tried to send AT commands via hyperterminal with 115200 and 57600 baudrate.

I checked the cable for serial comms and it works fine.

I tried to syncronize the link using A and after 2-3 senconds im sending "AT" command but no response from SIM900D.

Have you found any solution to this problem?

I dont know what should i do next..

ckshivaram

check if you can generate that baud rate again........
is there any ignition key/ button in the modem ...

andrei.tarziu

Newbie level 2
Serial port on computer work fine. I used it before on other projects.

At commands im sending are in this format:

AT <CR>

Is that ok?

I olse tried :

AT<cr><lf>

I have a short in pin RF_signal and GND on the chip when the EVB is powerd down. Is that normal because is the second chip with this problem and im starting to think thats the way is should be.

Primark

Newbie level 6
Ah try this one, I learned a few tricks while abruptly testing my sim900d. Check your power source, if your using 5V 1.5A power supply, it might not be enough, during bootup and the sim900D is connecting to a network it consumes a lot of power as a result if you have insufficient power it will fail. My sim900D has tolerance upto 7V so I created my own power supply upto 6.9V. As a result it responds perfectly. Oh and one more note. If you have by chance previously set the baudrate of the sim900D to another rate like 9600. It won't function properly. So what I'm trying to say is first set a higher voltage source then try different baud rates. If you receive garbage characters your getting there. Good luck

---------- Post added at 02:15 ---------- Previous post was at 02:14 ----------

And about my code above. It's actually working fine haha learned a very cheap trick to make the code work. Thanks anyways

homermike

Junior Member level 3
Ah try this one, I learned a few tricks while abruptly testing my sim900d. Check your power source, if your using 5V 1.5A power supply, it might not be enough, during bootup and the sim900D is connecting to a network it consumes a lot of power as a result if you have insufficient power it will fail. My sim900D has tolerance upto 7V so I created my own power supply upto 6.9V. As a result it responds perfectly. Oh and one more note. If you have by chance previously set the baudrate of the sim900D to another rate like 9600. It won't function properly. So what I'm trying to say is first set a higher voltage source then try different baud rates. If you receive garbage characters your getting there. Good luck

---------- Post added at 02:15 ---------- Previous post was at 02:14 ----------

And about my code above. It's actually working fine haha learned a very cheap trick to make the code work. Thanks anyways

Hello good day everyone... have same problem here with sim900D

i have already tried the sim500 and used it successfully in other project... we'v already done it on our final pcb for production...

we have another project and now using the sim900D due to its availability and a BATTERY CHARGE function which sim500 dont have...

same problem we encountered now.. that every wiring connection is up and correctly done... but when issuing AT COMMANDS on it.. we get reply but garbage and even tried all of the baudrates available still garbage being recieved... i even put a LED to the NETLIGHT pin to insure that the module is running... and it was blinking meaning the module is up and ready to receive AT COMMANDS... but sadly no good reply has been recieved...

iv tried giving 3.6v and 2A supply on it but still no good data recieved...

hope y ou can help me guys...thanks...

ckshivaram

try to change tx and rx pins on one side of cable...
Check your baud rate using AT+IPR? and set terminal baudrate once the modem responds.

---------- Post added at 12:01 ---------- Previous post was at 11:59 ----------

getting garbage is an indication of wrong baudrate settings.. try to reset to factory settings by doing AT&F command. re-power on modem and check baud rate of it.

homermike

Junior Member level 3
try to change tx and rx pins on one side of cable...
Check your baud rate using AT+IPR? and set terminal baudrate once the modem responds.

---------- Post added at 12:01 ---------- Previous post was at 11:59 ----------

getting garbage is an indication of wrong baudrate settings.. try to reset to factory settings by doing AT&F command. re-power on modem and check baud rate of it.

Thanks for the reply... i already did alternate the rx and tx of the data cable.. still can't get reply from the module...

also if sending AT+IPR surely can't get reply from the module also...
ill try to reset to factory...

is sim900D really a TTL level? should i try to use RS232 instead of TTL232?

big thanks...

ckshivaram

you have one more alternative. connect the modem to terminal and keep on changing the baud rate in the terminal and re-power ON the modem after every settiing and send at command and see the response.. i feel the baud rate has been modified in the modem to a higher baud rate.....

Primark

Newbie level 6
there are two things you have to do, well as for the modem (sim900d), you have to test it via the hyperterminal, chances are it is not working properly, you need a ttl to rs232 converter to attach it to the serial port of the computer, then test if you can receive a response from the modem, then create a program that will keep feeding "at" via the rx tx of the mcu, attach the mcu to the serial of the computer as well and test it via the hyper terminal. if both of them are functioning correctly then this ought to do the trick. connect the mcu and the modem via a max232, this will increase the error tolerance of the communication between the mcu and the modem.

homermike

Junior Member level 3
good day...

so your saying that the sim900D is RS232 level not TTL232 level?

i have a special cable called DCU11, its a USB with Prolific Driver... the cable has a TTL232 output already... im using the cable for communication between MCU and PC/LAPTOP or any device with SERIAL TTL... so when im going to use the cable, the PC/LAPTOP is acting like the MCU... in a TERMINAL Software e.g. Hyperterminal i just going to issue AT COMMANDS and expecting a reply from sim900D... i used the same cable in communicating sim500W and no problem at all...

this is what im going to do before i go on the MCU thing... want to test first before going to MCU/Hardware...
ill just try first what "ckshivaram" suggested me to do... then if ever not successful ill construct MAX232 crkt... but im really thinking that sim900D is not in RS232 level... most of the gsm module is in TTL level for sure...

raowakeel

Points: 2