Go Down

Topic: [SOLVED]Siemens TC35 serial communication (Read 2456 times) previous topic - next topic

zeroG

Aug 07, 2012, 04:44 pm Last Edit: Aug 09, 2012, 07:59 pm by zeroG Reason: 1
Hello  :)
I'm using a Siemens TC35 module to send SMS with Arduino. I wrote  a simple sketch and it works, i can send SMS with analog data from sensors.
Now i want to know when the modem registers on the network, so first of all i send the "AT+CREG=1" command but....how can i see the modem answer on serial monitor? I tried with the following sketch, but it doesn't work. I don't know how serial communication works...  :smiley-roll-sweat:

Code: [Select]
#include <NewSoftSerial.h>
NewSoftSerial cell(7,8);
char inchar;

void setup(){

 Serial.begin(9600);
 cell.begin(9600);
 delay(1000);
 
 }

void loop(){
 cell.print("AT+CREG=1\r\n");
 
 if(cell.available() >0){
    inchar = cell.read();
    Serial.print("Answer1: ");
    Serial.println(inchar);
     }
 delay(2000);

}


The Answer1 should be "OK"...but i can't see neither "Answer1:" nor "OK".

Can you help me?

PaulS

Code: [Select]
  cell.print("AT+CREG=1\r\n");
You want to send this over and over? If not, it belongs in setup().

Code: [Select]
  if(cell.available() >0){
Tests how many bytes of data there are to read.

Code: [Select]
     inchar = cell.read();
Reads ONE of them.

Quote
The Answer1 should be "OK"

No, it should be 'O' or 'K', assuming that the TC35 responded to the request. You'll have to look at the documentation, and confirm that +CREG=1 is a valid AT command, and that it causes the phone to generate a response.

Once you know whether the phone has registered, why would you want to send the same command again?

zeroG

Hi,
i don't need to send the command every loop, i put it there to check if it works. After i'll need it to send SMS.
You said that i receive "O" and then "K"...what if i use a cycle to store all chars into an array?
Code: [Select]

      for(i=0;i<max;i++){
        inchar[i] = cell.read();
      }


The command AT+CREG=1 is correct, i used the same command list to send SMS, and it worked.
Thanks for your reply

PaulS

Quote
what if i use a cycle to store all chars into an array?

If you are getting a response at all, that is a good idea. If not, then it won't help.

Don't try to read what hasn't arrived yet.

zeroG

Ok i found a solution. The following code may seem stupid, but in this way i understood how serial communication works.

Code: [Select]
#include <NewSoftSerial.h>

NewSoftSerial cell(7, 8);
int i=0;

void setup()
{
  cell.begin(9600);
  Serial.begin(9600);
  Serial.println("Starting communications...");
  delay(5000);
}

void loop(){
 
  Serial.print("Loop: ");
  Serial.println(i);            //number of this loop
 
  cell.print("AT\r\n");      //put here the AT command followed by \r\n
     
      while(cell.available()>0){
        Serial.print((char)cell.read());   //reading GSM result
      }
     
  Serial.println("End loop.");
  i++;
  delay(3000);
}


There's a problem: during the first loop (loop 0) there's no results, i start receiving data from loop 1. I tried to put a delay(5000) in the setup, but it doesn't change:
(Serial monitor)

     Loop 0

     End loop

     Loop 1
     AT
     OK
     End loop
     ....


PaulS

Quote
I tried to put a delay(5000) in the setup, but it doesn't change:

Why, if you want to wait for a reply from the AT command, would you put the delay() BEFORE sending the AT command?

zeroG

Because maybe the modem needs time to start, i don't know. However, ignore that line...
I'm reading the manual, maybe i'll find something useful to solve this problem.

PaulS

Well, the hint was there for you to add a delay() AFTER sending the AT command, before trying to read the response.

zeroG

#8
Aug 09, 2012, 07:58 pm Last Edit: Aug 09, 2012, 08:43 pm by zeroG Reason: 1
I didn't use this method before because the problem appears only during the first loop.
I solved putting this line after the AT command (n is the loop number):

Code: [Select]

cell.print("AT\r\n");
if(n==0)(delay(3000));


Now it works!
Thanks for your help  :)

can you give me the part of code to read simply sms to a tc35 board witjh arduino uno ?

Go Up