Hi
I have problem with serial communication with arduino uno and 3G Shield SIM5216E ItedStudio. Sketch sends AT command successfully through serial but not able to get reply. Serial monitor just shows AT+CMGF=1 nothing happens after this. If i am connecting shield directly to PC through USB To Serial COM port its working fine in hyper-terminal. Showing all Reply's and messages. Please help what i am missing? Thanks in advance.
int led = 13;
int onModulePin = 8; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send
int count = 0;
int n_sms,x,sms_start;
char data[256];
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i = 0;i < 5;i++){
delay(5000);
}
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(100);
x = 0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}
while(!((data[x-1] == 'K') && (data[x-2] == 'O')));
}
void loop(){
while (count < timesToSend){
delay(1500);
while(Serial.available()!=0) Serial.read();
Serial.println("AT+CPMS=\"SM\",\"SM\",\"SM\""); //selects SIM memory
Serial.flush();
for (x=0;x < 255;x++){
data[x]='\0';
}
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!((data[x-1] == 'K') && (data[x-2] == 'O')));
x=0;
do{
x++;
}while (data[x] != ' ');
x++;
n_sms=0;
do{
n_sms*=10;
n_sms=n_sms + (data[x]-0x30);
x++;
}while (data[x] != ',');
Serial.print(" ");
Serial.print(n_sms,DEC);
// Now it shows the total number of SMS and the last SMS
Serial.println(" SMS stored in SIM memory. Showing last SMS:");
Serial.print("AT+CMGR="); //Reads the last SMS
Serial.println(n_sms-1,DEC);
Serial.flush();
for (x=0;x < 255;x++){
data[x]='\0';
}
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
if((data[x-1] == 0x0D) && (data[x-2] == '"')){
x=0;
}
}
while(!((data[x-1] == 'K') && (data[x-2] == 'O')));
data[x-3]='\0'; //finish the string before the OK
Serial.println(data); //shows the message
delay(5000);
count++;
}
}