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.

Problem with Atmega8 USART interrupt

Status
Not open for further replies.

Sharagim

Advanced Member level 4
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,050
Hi,
I am trying to run receive interrupt on atmega8 USART, and failed.
Without interrupt it is ok and working but seems the "USART_RXC_vect" never fire.
thanks in advance for any comment which help me to solve it.

Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define F_CPU 8000000
#define USART_BAUDRATE 19200
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)


ISR(USART_RXC_vect)
{
   char ReceivedByte;
   ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived"
   UDR = ReceivedByte; // Echo back the received byte back to the computer
}

int main(void){
   UBRRL = BAUD_PRESCALE;
   UBRRH = (BAUD_PRESCALE >> 8);
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
   UCSRB |= (1 << RXEN) | (1 << TXEN);
   UCSRB |= (1 << RXCIE);
   sei();
    while(1)
    {

    }
}
 

diegobb

Member level 5
Joined
Jun 12, 2003
Messages
85
Helped
10
Reputation
20
Reaction score
4
Trophy points
1,288
Location
Montevideo - Uruguay - South America - Earth
Activity points
576
I don't remember exactly where it it's located in the datasheet, but when you write to 16 bit registers (Like UBRR) you must write the high byte first.

Try inverting the order in which you write in UBRR, this way:
Code:
UBRRH = (BAUD_PRESCALE >> 8);
UBRRL = BAUD_PRESCALE;

Look at the page 135 of the datsheet.

Best Regards.
 

Sharagim

Advanced Member level 4
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,050
Thanks for your reply .
I did as you mention but nothing happened, same as before!
 

Sharagim

Advanced Member level 4
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,050
Finally I found the problem .
I am using AVRStudio5 and in that I have to use "ISR(USART__RXC_vect)" instead of "ISR(USART_RXC_vect)" .

BR,
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,032
Trophy points
1,393
Location
Greece
Activity points
64,375
I have only checked AVR studio 5 when it was a beta version, I keep using the version 4 but it doesn't make sense, why would they change the interrupt definition in the new version?
So in the m8 header how is USART_RXC_vect defined, it has to be defined or you would get an error?
 

Sharagim

Advanced Member level 4
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,050
No error.
I try to put some values like "ISR(USART_RXC_vect1111)" and compiled without error too !!!!
 

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
752
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,065
It will not show error.. But will show warning...

like:
test_uart.c:48:1: warning: 'USART_RXC_vectttttttt' appears to be a misspelled signal handler
(a test on avr-gcc linux)

But why they made it "USART__RXC_vect" instead of "USART_RXC_vect" !!:roll:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top