1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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++
} 
\$\endgroup\$
  • \$\begingroup\$ my number is right and i am getting a call but when I include it in this code, i didnt get any call. what is this uart_buffer, whats its size.? empty i think is not a keyword. can i use NULL \$\endgroup\$ – anna carolina Aug 3 '15 at 7:06
  • \$\begingroup\$ this is just pseudo code, uart_buffer is 1 byte size, so you store byte per byte in your byte array buffer. @annacarolina \$\endgroup\$ – Junior Aug 3 '15 at 7:11
  • \$\begingroup\$ Can you tell me why i am getting a series of ATD commands when ext interrupt is fired.? \$\endgroup\$ – anna carolina Aug 3 '15 at 7:14
  • \$\begingroup\$ You don't get series of AT commands, you get series of bytes and reason you're getting them is because you are receiving string answer from your GSM module which is array of chars. @annacarolina \$\endgroup\$ – Junior Aug 3 '15 at 7:16
  • \$\begingroup\$ you said i am receiving string but I am transmitting the string?? \$\endgroup\$ – anna carolina Aug 3 '15 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.