code catchs not GPRS modem response or why is this code not working

I'm trying to get the FTP demo code for a SIM900 module working. I can make the connection by using the AT commands in the code in general but the code is somewhere hanging. The problem may be that serial for debugging and serial for communication between Arduino and GPRS modem are sharing the same pins, pin 0 and 1 for TX/RX, but I don't know.

What I did: I uploaded the code, before I commented out the parts for the pin because the SIM card I'm using has no pin activated.

After uploading I disconnected the cables from USB (I use a Seeeduino Stalker with a FTDI cable) and connected TX/RX vice versa, so I can "sniff" the GPRS-Arduino communication. I tried also to disconnect FTDI totally but could not see any updated file.

What I see is that the sketch repeats always AT - OK and again AT - OK. So it seems that the function "sendATcommand" causes the problem. A said before firing the AT via this code is working http://www.old.gprsbee.com/#!test-sketch/c10sq s I assume the problem is not the hardware.

Code I'm using is https://www.cooking-hacks.com/documentation/tutorials/gprs-gsm-quadband-module-arduino-raspberry-pi-tutorial-sim-900#step6 (sorry too big to include it here.)

Here is the code I'm speaking about attached

demo-sim900-ftp.ino (9 KB)

Seems that this section causes problems

   while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 
            sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );