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.

Atmega2560 USART issue with interrupt...

Status
Not open for further replies.

Krv Perera

Newbie level 2
Newbie level 2
Joined
Oct 8, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
19
// This code waits for a character and transmits the character back (with interrupts)


Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define F_CPU 16000000UL
#include <avr/io.h>
#include <stdint.h>                     // needed for uint8_t
#include <util/delay.h>
#include <avr/interrupt.h>
 
 
#define FOSC 16000000                       // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD -1
 
 
volatile char ReceivedChar;
 
 
int main( void )
{
    //cli();
    DDRB = 0xFF;    //LED off
    PORTB = 0x00;
    UCSR0B |= (1 << RXEN0) | (1 << TXEN0);      // Enable receiver and transmitter
                        //RX interrupt enabled
    UCSR0C |= (1 << UCSZ01);// | (1 << UCSZ00);    // Set frame: 8data, 1 stp
    
    /*Set baud rate */
    UBRR0H = (( MYUBRR ) >> 8);
    UBRR0L = MYUBRR;
    UCSR0B |= (1 << RXCIE0);
    sei();
 
    
    while(1)
    {
        
        if( ReceivedChar == 'C' || ReceivedChar == 'c'){
            PORTB |= (1<<PORTB5);
            _delay_ms(500);
        }
        
        PORTB = 0x00;
        _delay_ms(500);
        PORTB = 0xFF;
        _delay_ms(500);
        // Main loop
    }
}
 
ISR (USART0_RX_vect , ISR_BLOCK)
{
    
    ReceivedChar = UDR0;
    UDR0 = ReceivedChar;
    //sei();
}



Above is my code but my Interrupts not working as I intended
 

Dear milan,
Thank you for the reply but I think it is not relevant to Atmega2560 and I don't have a "USART_RXC_vect" & instead
I have "USART_RX_vect " for atmel studio.
Do you know a proper way to debug it so I could find the issue.
 

Are you using AVR Studio with WinAVR or Atmel Studio with gcc ?

- - - Updated - - -

I made a working code for Mega2560 at 16 MHz Clock. USART0 is used. Tested in Proteus 8.1. See if it works in hardware.

110149d1412859800-sim.png
 

Attachments

  • Atmel Studio 6.2 Projects.rar
    105.6 KB · Views: 74
  • sim.png
    sim.png
    40.3 KB · Views: 96

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top