I would strongly suggest to use hardware USART and if possible interrupts like Darrels Instant Interrupts. It will assure you no lost characters.
Secondly, I see that you are not checking if the modem has replied with OK or an error, except once. Not all commands have the same processing time. So it is a good practise to confirm that the device has accepted succesfully the command by monitoring its response.
Ioannis
Bookmarks