SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Nathaniel Lewis
#15978
:? Can some one give me some code to run the M8 and M32 USART in Win-AVR(ie. AVR-GCC c code for the avr)? I've looked at the datasheet but it won't work.
Nathaniel
By soda
#27555
Nathaniel Lewis wrote::? Can some one give me some code to run the M8 and M32 USART in Win-AVR(ie. AVR-GCC c code for the avr)? I've looked at the datasheet but it won't work.
Nathaniel
try to look to datasheet, there is a two registers sharing one address location (i dont remember their names). register you write to depends on state of one bit (msb or lsb). but as I wrote, you have to read datasheet :) (furtunately there is this Ctrl+F thing :) )
By bibinjohn
#39262
try this code
/*----------------------------------------------------------------
-----------------MAIN FUNCTION------------------------------------
-----------------------------------------------------------------*/

void main()
{
unsigned char a;
//lcd initializationsa
Init_Ports();

InitUART( 25 ); /* Set the baudrate to 2400 bps using a 1MHz crystal */
for(;;) /* Forever */
{

TransmitByte(0x99); /* Echo the received character */
Receive_PORT=ReceiveByte();

}
}

/*----------------------------------------------------------------
------------FUNCTIONS TO Initialize UART--------------------------
-----------------------------------------------------------------*/

void InitUART( unsigned char baudrate )
{
UBRRL = baudrate; /* Set the baud rate */
UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
}
/*----------------------------------------------------------------
------------FUNCTIONS TO READ UART-------------------------------
-----------------------------------------------------------------*/
unsigned char ReceiveByte( void )
{
while ( !(UCSRA & (_BV(RXC))) ); /* Wait for incomming data */
return UDR;/* Return the data */
}

/*----------------------------------------------------------------
------------FUNCTIONS TO WRITE UART-------------------------------
-----------------------------------------------------------------*/
void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}



void Init_Ports(void)
{
Receive_DDR=0xFF; //setting that port for output
Receive_PORT=0XFF; //setting all bits high for starting
}


See the frequency you are using and set baud rates properly, otherwise you will get errors. See the troubleshooting tips
http://avrmicrocontroller.googlepages.c ... lport.html

Bibin John
www.bibinjohn.tk
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]