i am sending 4 bytes of data from my Pc serially to my atmega16. i use UART. one technique is to use the functoins given in datasheet but they block rest of the code as they use polling. so i am using a while loop. but i am unable to understand the structure of the code when the while loop starts.. please help me in this. thnx
#include <avr/io.h>
#define FOSC 1843200// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
void UART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}
int main( void )
{
int i = 0;
unsigned char my_data [4];
UART_Init ( MYUBRR );
while (1)
{
if (UCSRA & (1<<RXC))
{
my_data[i] = UDR;
}
i++;
if (i == 3)
{
/*my next code here and once thats done, its again in uart receive mode*/
i = 0;
}
}
}