title: receiving char * from UART of AVR
body: <p>I want to receive a string(pointer to characters) by UART using ATMEGA16. I burned this code on the kit then I used hyperterminal (realterm) and made a test to input a string ("on") and if it is received then portc (LEDS) will be set to 1 but it doesn't work ... anyone!? :D </p>
  
  <p>Implementation of functions</p>
  
  <pre><code>#include &lt;avr/io.h&gt;
  
  #define F_CPU 8000000UL
  unsigned char *x;
  
  #define USART_BAUDRATE 9600
  #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
  
  void uartinit()
  {
      UCSRB |= (1 &lt;&lt; RXEN) | (1 &lt;&lt; TXEN);   
                      // Turn on the transmission and reception circuitry
      UCSRC |= (1 &lt;&lt; URSEL) | (1 &lt;&lt; UCSZ0) | (1 &lt;&lt; UCSZ1); 
                      // Use 8-bit character sizes
  
      UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
                             // into the low byte of the UBRR register
      UBRRH = (BAUD_PRESCALE &gt;&gt; 8); // Load upper 8-bits of the baud rate value..
                                    // into the high byte of the UBRR register
  }
  
  void uartsend( unsigned char *data )
  {
      while(*data != '\0')
      {
          /* Wait for empty transmit buffer */
          while ( !( UCSRA &amp; (1&lt;&lt;UDRE)) );
          /* Put data into buffer, sends the data */
          UDR = *data;
          data++;
      }
  
  
      while ( !( UCSRA &amp; (1&lt;&lt;UDRE)) );
  
      UDR = *data;
  
  }
  
  unsigned char * uartrecieve()
  {
      //unsigned char i=0;
      //    unsigned char * x;
  
      /* Wait for data to be received */
  
      //    char * ptr = &amp;UDR;
  
      while ( !(UCSRA &amp; (1&lt;&lt;RXC)) );
  
      while(UDR != '\0')
      {
          *x = UDR;
          x++;
          while ( !(UCSRA &amp; (1&lt;&lt;RXC)) );
      }
      *x = UDR;
  
       return x;
  } 
  </code></pre>
  
  <p>and this is main function</p>
  
  <pre><code>#include &lt;avr/io.h&gt;
  #include "UARTInterface.h"
  
  
  int main(void)
  {
      DDRC=0xFF;
      uartinit();
      while(1)
      {
          unsigned char *y;
          y=uartrecieve();    
          if(strcmp(y,"on")==0)    
          {
              PORTC=0xff;
  
          }
          //uartsend(y);
          //TODO:: Please write your application code 
      }
  } 
  </code></pre>