Search code examples
gccavruartsim900

SIM900: How to be sure how much time to wait between serial(UART) transmit and receive



i have written a library in C for using the SIM900 GSM with my uC but it has many many bugs. Sometimes it works sometimes not. My hardware works fine I think.

I rewrote it and made sure that the basic functions are bug free.

  • SIM900_transmit( char* );
  • SIM900_reveive( char** );
  • SIM900_on();
  • SIM900_off();

Now I want to write the SIM900_command function that will use SIM900_transmit( char* ) and SIM900_reveive( char** );

So my detailed question is:

How to know how much time to wait between AT command and receiving the answer from SIM900. I do not want to just put _delay_ms(1000).

Thanks in advance...


Solution

  • Usually, you wait until a character is available and then receive it. Have a look here. There you have for AVR devices with a single UART:

    unsigned char uart_recieve (void)
    {
        while(!(UCSRA) & (1<<RXC));
        return UDR;
    }
    

    So, with while(!(UCSRA) & (1<<RXC)); you basically block execution until there is a character available at the uart.