Let's Make Robots!

**USART Help**

I have been on this for past 4 hours and tried all possble combination on initilization in order to send one character to the UDR through USART. I need help or i will lose it here !

i am using avrstudio5 with usbusart and i also tried debugging through the simulator. i would check all bits are set accordingly but never would the UDR be set and after three iteration it hangs around the while (!(UCSRA &(1<<UDRE))); i also tried the printf() and ofcourse not even a sign of life except at somet points it asked me for the stdlio.c files

i need help cause i want to get my readings from adc using this. thank you

 


 

 

#define F_CPU 1000000UL //1MHZ Frequency, required for util/delay.h

#define BAUD 9600 //Baud rate

#define MYUBRR (F_CPU / 16 / BAUD) - 1 // UBRR

#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) // macros: verifies if the bit is set

 

#include <avr/io.h>

#include <avr/interrupt.h>

#include <avr/iom8.h>

#include <inttypes.h>

#include <util/delay.h>

#include <stdio.h>

 

char i;

 

void USART_init1(){

UBRRL=0X06;

UCSRB=0X18;

UCSRC=0X86;

}

 

void USART_init2(){

UBRRH = (uint8_t)((MYUBRR)>>8); // set the baud rate == 6

UBRRL = (uint8_t)MYUBRR;

UCSRC =(1 << URSEL);

UCSRC |= (1 << UCSZ1) | ( 1 <<UCSZ0 ); 

UCSRB |=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);

}

void USART_transmit(unsigned char data){

while (!(UCSRA &(1<<UDRE)));

UDR=data;

}

 

unsigned char USART_receive(void){

while (!(UCSRA & (1<<RXC)));

return UDR;

}

 

int main (void)

{

//USART_init1( );

USART_init2();

while (1){

i= 'a';

USART_transmit(i);

printf("A");

}

}

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Could it be possible the the usart IC is not functioning? i found some self loop tests: atmega class B. is this one good or is there another one that tests the chip? 

My only problem is in the AVR studio 5 the udr does not get updated when something is written, i dont know if it is suppose to.

 

any help is appreciated

 

thanks

 

oleg