Sharagim
Advanced Member level 4
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.
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)
{
}
}