0

I have been struggling with usart interface between these two devices. After the code has been ran, i can see TX and RX flashing, but no message actually passes through, which is my ultimate goal. Any idea how to troubleshoot this problem. The code is kind of borrowed from another stack question which has not been answered

    #define F_CPU 7372800UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>



#define FOSC 1843200// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1

void USART_Init( unsigned int ubrr){
    /* Set baud rate */
    UBRRH = (unsigned char)(ubrr>>8);
    UBRRL = (unsigned char)ubrr;
    /* Enable receiver and transmitter */
    UCSRB = (1 << RXEN) | (1 << TXEN);
    /* Set frame format: 8data, 2stop bit */
    UCSRC = (1 << URSEL) | (1 << USBS) | (3 << UCSZ0);
}

void USART_Transmit( unsigned char data ){

    /* Wait for empty transmit buffer */
    while ( !( UCSRA & (1<<UDRE)) )
    ;
    /* Put data into buffer, sends the data */
    UDR = data;

}

void USART_Transmits(char data[] ) {
    int i;

    for(i = 0; i < strlen(data); i++) {
        USART_Transmit(data[i]);
        _delay_ms(300);
    }
}

unsigned char USART_Receive( void ){

    /* Wait for data to be received */
    while ( !(UCSRA & (1<<RXC)) )
    ;
    /* Get and return received data from buffer */
    return UDR;
}



int main( void ){
    DDRA = 0xff;
    PORTA = 0xff;
    USART_Init ( MYUBRR );

    char text_mode[] = "AT+CMGF=1";
    char send_sms[] = "AT+CMGS=";
    char phone_number[] = "0038**********";
    char sms[] = "gsm/gprs sadness";

    USART_Transmits(text_mode);
    _delay_ms(1000);

    USART_Transmits(send_sms);
    _delay_ms(1000);

    USART_Transmit(34);
    _delay_ms(300);

    USART_Transmits(phone_number);
    _delay_ms(300);

    USART_Transmit(34);
    _delay_ms(300);

    USART_Transmit(13);
    _delay_ms(300);

    USART_Transmits(sms);
    _delay_ms(1000);

    USART_Transmit(26);//ctrl+z
    _delay_ms(300);

    //USART_Transmit(13);//enter
    _delay_ms(3000);

    while(1){   
        //USART_Transmits("alfa");
        //_delay_ms(200);
    }

    return 0;
}
Mile
  • 1
  • 1
  • You may want to add \r (CR, code 13) after AT+CMGF=1 – AterLux Mar 07 '19 at 19:28
  • I was working with GSM modules and there is a plenty reasons that come to my mind. Is that okey with diffrent F_CPU and FOSC for an USART? Did you cross RX/TX with your module? Are you sure atmega and your sim900 are on the same logic level (probably 5V or 3V3)? This module need some time to connect to services. You should read about it in datasheet for sim900. Finally you can use USART receive and ask sim900 "are you ready?" and after module acceptance use your commands. You should rely on answers of module. If it's possible try to use something like terminal and do this commands by hand. – dunajski Mar 08 '19 at 05:53

0 Answers0