Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial in AVR ATMEGA8535

Status
Not open for further replies.

zhi_yi

Full Member level 4
Joined
Feb 2, 2005
Messages
196
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,548
interrupt atmega8535

hi, please help me how to interface to serial interrupt in ATMEGA8535, i got difficulty in how to set the baudrate of asynchronous tranmission mode. I read from its datasheet that UBRR (12 bit) contain of UBRRH (4 bit) and UBRRL (8 bit). and I use ICC AVR's application builder to build the program, and it said that the UBRR should be "25" if I want the baudrate to be 9600, what does "25" means? how to assign it into UBRRH and UBRRL? and I want to use the serial in interrupt mode, are there any program examples? Thanks a lot for your time.
 

ubrrl = 0x19; //set baud rate lo ubrrh = 0x00;

Thanks ckshivaram,

btw, i've read the datasheet that you uploaded. can you please guide me step by step what should i do if i want to make a program that would receive data from PC and then the AVR would send it back to PC (echo the received data)? i checked that there are nothings wrong with my hardware connection. and i tried to make a program using ICC AVR, here is the code:

//ICC-AVR application builder : 5/23/2008 11:06:09 AM
// Target : M8535
// Crystal: 4.0000Mhz

#include <iom8535v.h>
#include <macros.h>

void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}

//UART0 initialize
// desired baud rate: 9600
// actual baud rate:9615 (0.2%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x19; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

/* Read and write functions */
unsigned char ReceiveByte( void )
{
while ( !(UCSRA & (1<<RXC)) ); /* Wait for incoming data */
return UDR; /* Return the data */
}

void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (1<<UDRE)) ) ; /* Wait for empty transmit buffer */
UDR = data; /* Start transmission */
}

void main()
{
init_devices();
while(1)
{
TransmitByte( ReceiveByte() ); /* Echo the received character */
}
}

from the program above, i test it using a program in PC that could send and receive serial data, when i send a character for example 'A', the AVR return it to the PC with a wrong character (unreadable character), could you please help me out, why does it happen? and what should i do to fix the program? once again, thanks a lot.
 

how to interface atmega8535 to pc

Hi; the probable reason for not getting the output is that you are not clearing the flag UDRE, and RXCafter the operation. if it is one then it will not receive the data again. so everytime you come out of the loop make that flag = 0; Think it is done by the controller only.

Little busy at office, will look into this whenever I get bored from my work. Will give you solution soon.

by the way which crystal are you using. use 11.0592Mhz it will solve the problem.
Check if the settings of the hyperterminal where you are seeing the output is configured properly, with hardware flow is configured as "none".

try this and let me know.
 

0x18 atmega8535

hey as long as I know, the crystal frequency can create error on data transfer, i'm not really remember about it but try to read the datasheet you'll find the table of error there.

one information for you, if you connect the USART with a computer that using LINUX OS (I don't know about windows OS) via RS-232 you can set baudrate uC by our own, but on computer side must be 19200 bps (there's no good explanation why must be like that).

ok good luck, don't forget keep read the datasheet and pay atention on UBRR error.


:D:D:D:D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top