ISR not vectoring?

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmega 128 STK 300
STudio4
noobie

The problem is, after the sei is enabled and after the normal wait of one instruction to act onh any interupts, the code "resets" back to the beginning, at first I checked for any other interupts causing this,but I found none (made sure reset pin was held high,no watchdog). I also monitored MCUCSR . I did see that I get a zero FLag when it goes back to the beginning of main ("reset"). Also I get build error ;

../FreakADCintrpt.c:259: warning: return type defaults to `int'
../FreakADCintrpt.c: In function `ISR':
../FreakADCintrpt.c:259: warning: type of "ADC_vect" defaults to "int"
../FreakADCintrpt.c:271: warning: control reaches end of non-void function

,so I think ISR is not being recognized as a place to vector to, and it has nowhere to go?

Could it be an optimization or fuse setting?

My code,is this code, from the ADC tutorial, I started posting there, but i remembered that someone suggests, it's not a good idea to tack onto long old threads...

include 
#include 

 
int main (void)
{
   PORTB|= (1 << 2); // Set LED1 as output
   DDRG |= (1 << 0); // Set LED2 as output

   ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set ADC prescaler to 128 - 125KHz sample rate @ 16MHz

   ADMUX |= (1 << REFS0); // Set ADC reference to AVCC
   ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading

   // No MUX values needed to be changed to use ADC0

   ADCSRA |= (1 << ADFR);  // Set ADC to Free-Running Mode
   ADCSRA |= (1 << ADEN);  // Enable ADC

   
   
   ADCSRA |= (1 << ADIE);  // Enable ADC Interrupt
     sei();   // Enable Global Interrupt *******************

   //ADCSRA |= (1 << ADSC);  // Start A2D Conversions

    
   for( ;;)  // Loop Forever ********
   {
   }
}

 ISR(ADC_vect)
  {
   if(ADCH < 128)
   {
      PORTE |= (1 << 2); // Turn on LED1
     PORTG &= ~(1 << 0); // Turn off LED2
   }
      
   else
   {
      PORTE &= ~(1 << 2); // Turn off LED1
      PORTG |= (1 << 0); // Turn on LED2
   }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
../FreakADCintrpt.c:259: warning: return type defaults to `int'
../FreakADCintrpt.c: In function `ISR':
../FreakADCintrpt.c:259: warning: type of "ADC_vect" defaults to "int"
../FreakADCintrpt.c:271: warning: control reaches end of non-void function

These mean that the ISR is not registering properly, though I don't know why. It looks correct.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

since this is the code that was on the tutorial, I assume it it something on my end, that is different. Maybe during the compiling.

I'm a noob but could optimization settings or fuses (thinking,not)effect this?

Or somoehow my library is not working?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tried it and it compiled just fine (aside from the fact that I had to add the # in the first include). Are you sure that you are compiling it for the mega128?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oops bad copy and paste re: "#"

thanks for testing.

it Will compile and run for me, just with the above mentioned ISR warnings, and the resultant reset to beginning of main.

I'm trying to find and then look into my header file.

Yes under project config it is atmega 128 -OS optimization. But I tried it will other (maybe not all) optimizations, same result.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How are you compiling this? i.e. what is your compile command line, and your link command line?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it it is using avr-libc-1.6.4 interrupt.h

is that the correct library? at least it works for most other things, as well as the sei instruction.

i also pointed studio 4 to use a WINavr interrupt.h, with the same result.

hmmmmm....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi wrote:
Quote:
../FreakADCintrpt.c:259: warning: return type defaults to `int'
../FreakADCintrpt.c: In function `ISR':
../FreakADCintrpt.c:259: warning: type of "ADC_vect" defaults to "int"
../FreakADCintrpt.c:271: warning: control reaches end of non-void function

These mean that the ISR is not registering properly, though I don't know why. It looks correct.
Perhaps there was also an "include file not found" warning.
Often when I get that warning (why on earth is it just a warning?),
I get a slew of other messages that keep me from noticing it, i.e. the important one.

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EW, I will look into what my links are and compile command line, do I have to add something manually? (remember I am a noob). I am just using Rebuild all, not saying I know what I am doing, but this is maybe my 5th program ever so I have gotten others to work (just background info).

Skeeve, nope no missing header file warnings, just the ISR related ones.

I'll get back to it later today, I have to go align a car now ;-).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Placed after all the #includes,
this will tell you something you need to know.

#ifndef ISR
#error ISR not #defined
#endif

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In AVR Studio, after building, go to the Build tab (at the bottom) and select and copy the entire output of the build process. Paste it into a post here. This will contain all the command lines that are being executed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Steve.A

Did you use Studio4 when it compiled for you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe you have a super old version of winavr/libc. Find and read the interrupt.h file (same directory as io.h), or simply find it in the file list on the left in avr studio. If its not in the list, its not being included (io.h must have been found, or you would get lots of errors). If no ISR define in the header, maybe you have an old version (real old).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I used AVR Studio.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I found the problem (thanks to all of you), now I need to know what to do about it.

in the external dependencies , the interrupt.h had no ISR routine in it,(but has sei routine) the path was to a WinAVR-20080610\avr\include\avr\interrupt.h.

Now, in my avr-lib-c1.6.4 interrupt.h, it does have the ISR routine, how come winavr is not using that one?

Under project config, I have use WINAVR checked...but somehow should I not be using avr-lib-c1.6.4 ?

i tried troubleshooting before by using the lib-c header file with "quotes" to make sure it was using that one, but ...I'll try it again.

here was the build output:

rm -rf test.o test.elf dep/* test.hex test.eep test.lss test.map
Build succeeded with 0 Warnings...
../test.c:30: warning: return type defaults to `int'
../test.c: In function `ISR':
../test.c:30: warning: type of "ADC_vect" defaults to "int"
../test.c:42: warning: control reaches end of non-void function
avr-gcc.exe -mmcu=atmega128 -Wl,-Map=test.map test.o -o test.elf
avr-objcopy -O ihex -R .eeprom test.elf test.hex
avr-objdump -h -S test.elf > test.lss

avr-mem.sh: /c/WinAVR-20080610/bin/avr-size: Invalid argument
AVR Memory Usage:
-----------------
Device: atmega128

Program: 0 bytes (0.0% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)

Build succeeded with 3 Warnings...

******************************************************
what does invalid memory argument mean??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

O.K so, the library in my WinAVR-20080610 folder seems out of date, the interrupt.h file in it, is from 2002, the lib-c 1.6.4 one is from 2007 and has the ISR function in it, is it safe to replace the existing lib c folder and replace it with the lib c 1.6.4?

I have no idea why the WinAVR-20080610 release I have has an old library, isn't '610 pretty current?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I re downloaded WinAVR 20080610, and checked the interrupt.h as including the isr routine, it did and everything works....I have no idea how the other version of WinAVR with the same file name had an old library in it...

Thanks everyone...now I can get back to the coding!! :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

is it safe to replace the existing lib c folder and replace it with the lib c 1.6.4?

Why try to tinker with the individual files of WinAVR. Just uninstall WinAVR completely, then delete any possibly leftover directories by hand, then install the latest WinAVR.

Installation programs are there for a reason..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]