EmbDev.net

Forum: µC & Digital Electronics ATMEGA 644 on Pollin NETIO: sei leads to reset/restart


von Michael H. (mh11)


Rate this post
useful
not useful
Hello all,

first of all: I hope that this is the correct forum, if not, please give 
me a hint.
2nd: I searched a couple of days, but did not find anything, so now, I 
need someone who likes to help me.

I run an Atmel ATMEGA 644 on a Pollin Net-I/O board and try "from 
scratch" to setup a simple timer 0 interrupt.

The code looks like this:
1
#include <stdint.h>
2
#include <avr/io.h>
3
#include <avr/interrupt.h> 
4
#include <util/delay.h>
5
6
ISR(BADISR_vect)
7
{
8
// catch up all interrupts for which no ISR is defined
9
}
10
11
ISR (TIMER0_OVF_vect) 
12
{
13
  PORTC |= (1<< PC1);           // LED on
14
  _delay_us(200);
15
  PORTC &= ~(1<< PC1);          // LED off
16
}
17
18
// ********************** main function **************************
19
int main(void) {        // main function begins here
20
21
  DDRC |= (1<<PC0) | (1<<PC1); // set C.0 and C.1 as output  
22
23
  TCCR0B = 1<<CS02;
24
  TIMSK0 |= (1<<TOIE0);        // unmask timer0 interrupt
25
26
  sei();                       // enable interrupts 
27
   
28
  for (;;) {
29
    PORTC |= (1<<PC0);         // LED on
30
    _delay_ms(200);
31
    PORTC &= ~(1<<PC0);        // LED off
32
    _delay_ms(200);
33
  
34
  }
35
36
  return (0);    // return from function main (never reached)
37
38
}

The strange thing is that the code after sei() is never reached, means 
the LED 0 is never blinking. If I comment out the sei() OR the TCCR0B = 
line, the LED 0 blinks.
(LED 1 stays dark in both cases)

If I try to use "external clock source on T0 Pin" (CS02 | CS01) the code 
"LED 0" is also reached, but obviously the ISR is not executed.

I also tried to configure Timer 1 with the same effect.

IMHO, the problem must be very trivial, but I don't have any clue 
anymore.

I really appreciate some ideas / hints from you, TIA!

von Michael H. (mh11)


Rate this post
useful
not useful
I set this myself to "Solved" (is there a formal way?).

As I found out today, I was a little bit confused, when I took over my 
makefile from another project (Bootloader), so this code was flashed 
into the bootloader section. Sure, interrupts in Bootloader are also 
possible, but need another interrupt tale. But, as I was using the 
"appl-interrupt table", the code could not work.

Removing the option LDFLAGS += -Ttext=E000 from the makefile did the 
trick, the code above is completely correct.

This, just that no one else uses his/her time to analyze my (phantom) 
problems!

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.