cavrusart

Why can't I put command in ATMEGA64A-AU serial?


I've bought an ATMEGA64A-AU and I connected its USART0 to FT232RL(USB to serial) and its USART1 to GSM module.

I use USART0 for monitoring only purpose and USART1 to communicate with GSM module.

I wrote these to enable USARTs:

void USART0_Init( unsigned int ubrr )
{
    UBRR0H = (unsigned char) (ubrr >> 8);
    UBRR0L = (unsigned char) ubrr;
    UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
    UCSR0C = (1 << USBS0) | (3 << UCSZ00);
}

void USART1_Init( unsigned int ubrr )
{
    UBRR1H = (unsigned char) (ubrr >> 8);
    UBRR1L = (unsigned char) ubrr;
    UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
    UCSR1C = (1 << USBS1) | (3 << UCSZ01);
}

And these to put char or string in each USART:

void usart0_putc (char send)
{
    while ((UCSR0A & (1 << UDRE0)) == 0) {};
    UDR0 = send;
}

void usart0_puts (const char *send)
{
    while (*send) {
        usart0_putc(*send++);
    }
}

void usart1_putc (char send)
{
    while ((UCSR1A & (1 << UDRE1)) == 0) {};
    UDR1 = send;
}

void usart1_puts (const char *send)
{
    while (*send) {
        usart1_putc(*send++);
    }
}

I used RX1 interrupt vector to get response from module:

ISR (USART1_RX_vect)
{
    data_in[data_count] = UDR1;
    if (data_in[data_count] == '\n') {
        command_ready = TRUE;
        data_count = 0;
    } else {
        data_count++;
    }

}

And the main function:

void main( void )
{
    sei();
    
    USART0_Init(MYUBRR);
    USART1_Init(MYUBRR);
    while(1){
        if (command_ready == TRUE) {
            memcpy(command_in, data_in, MAXCHAR );
            memset(data_in, 0, sizeof(data_in));
            usart0_puts(command_in);
            command_ready = FALSE;
        }
        
    }
}

It shows the response or anything like ringing and messages but the problem is , when I put some command to it by micro controller like putting this line before main while loop :

usart1_puts("ATD+545555555555;\r\n");

To call some number, the whole thing stops and not only it don't call that number but it stops showing responses from module, so I thought there is something wrong with the code.

Any help would be appreciated.


Solution

  • You have to change the line :

    UCSR1C = (1 << USBS1) | (3 << UCSZ01);

    to this : UCSR1C = (1 << USBS1) | (3 << UCSZ10);

    UCSZ01 bit belongs to USART0 not USART1 according to the datasheet!