Error interfacing GSM with Atmega32 using UART Interrupt

avrcgsmswitchesuart

I am interfacing GSM with atmega32 using uart interrupts. I am using an external interrupt which is fired when a user press a switch and uart receive interrupt to receive the response of GSM.

CODE:

int main(void)
{

   DDRC = 0xFF; //output led
   PORTD = 0x04; //PD2 high for switch interrupt
   serial_Init();
   GICR = (1<<INT0);
   sei();
   while(1)
    {

     }
}
ISR (INT0_vect)
{

   serial_Tx("ATD<number>;\r\n");
}

ISR(USART_RXC_vect)
{


}

My question is that whenever I press the switch, ISR is fired and command is executed but I didnt get any call. What could be the error? IS this because when I press switch, on my terminal I get a series of ATD command instead of single command. And I am also confused why I get series of ATD command instead of single command.

My next question is how can I receive response from GSM. we can only read single , byte that means do i need to use for loop to store it in a char array.?

Serial_Tx function:

void serial_Tx(char *str)
{
for (unsigned int i=0;str[i]!=0;i++)
{
    UDR=str[i];
    while(!(UCSRA&(1<<UDRE)));
}
} 

Serial_Rx function:

char serial_Rx()
{
while(!(UCSRA & (1<<RXC)));
return UDR;
}

OUTPUT:

enter image description here

Best Answer

My question is that whenever I press the switch, ISR is fired and command is executed but I didnt get any call.

Print bytes received from UART ISR on terminal, to see response from AT calling command, if you get 'OK', then number you wrote in AT command is called, if not your number is not called and you doing something wrong.

Is this because when I press switch, on my terminal I get a series of ATD command instead of single command?

You always get an answer from GSM module regardless of whether it is all right or not, in the form of array of bytes and before you want to print it somewhere, you need to store all of that data.

My next question is how can I receive response from GSM. we can only read single , byte that means do i need to use for loop to store it in a char array?

No for loop, use while loop in this case

int i = 0;
while(uart_buffer != empty)
{
    received_chars[i] = uart_buffer_char;
    i++
} 
Related Topic