Firstly you have no overflow protection on your scanf commands, you are reading until a new line character, if that happens to give you more than 29 characters then you'll overflow the buffer and if you're lucky crash.
Always limit the number of characters to match the buffer size.
Secondly, you're not setting the baud rate for the modem, the default is 9600 so you may be OK without doing this but it's always a good idea to set it just to be sure.
Maybe add debug code to report to the user exactly what it is sending to the modem.
And what do you get when read the modem reply byte by byte?
How long do you expect the modem reply to be? If it's more than will fit into the UART RX hardware buffer then you'll overflow and lose data.
Hello guys, I am working on a project that requires me to send AT commands to an SIM900 modem. I tried to make my Teensy 3.1 board into a serial interface between my Mac and the SIM900 modem, but I am having trouble receiving the response from the GSM modem. Here's my program:
The program just gets stuck at line 62 "gsm.scanf("%s", gsmrcv);". I tried to use a while loop and use "gsm.getc( )" to read one character at at time into the gsmrcv array, but it just gives me a bunch of random characters. I disconnected the Teensy board and tried another piece of code on Arduino, and it worked perfectly. Here's the code:
Please help! This project is due very soon. Thank you!