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.

Problem with Atmega8 USART interrupt

Status
Not open for further replies.

Sharagim

Advanced Member level 4
Full Member level 1
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,058
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)
    {

    }
}
 

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.
 

Thanks for your reply .
I did as you mention but nothing happened, same as before!
 

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,
 

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?
 

No error.
I try to put some values like "ISR(USART_RXC_vect1111)" and compiled without error too !!!!
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top