Problem in Running a Program in ATmega644P

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

Hi,

I am currently experiencing a problem in running my program using the ATmega644P.

What i want to do is to run a program (which is successfully loaded to the MCU through JTAG) once and stop the execution, after the whole code is completed. However, what happens now is that after successfully running the whole code, the MCU enters sleep mode, leaves the sleep mode, resets, and runs the whole program again (which I do not want to happen).

What then can I do? How do I prevent the MCU from reseting and running the whole program all over again.

Thank you very much in advance!

-Sherwin

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

Without seeing you code I can only guess; but I can think of two ways you get this type of behaviour.

1) You return from main(). If you are using avr-gcc (WinAVR) then the program jumps to _exit() if you ever return from main. I guess other compilers do the same. Solution: add a loop like this one to the end of main():

for(;;);

2) You have enabled the watchdog and end up in an endless loop without re-armoring the watchdog. This will also result in a reset of your CPU.

Thomas

pycrc -- a free CRC calculator and C source code generator

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

tpircher wrote:
Without seeing you code I can only guess; but I can think of two ways you get this type of behaviour.

1) You return from main(). If you are using avr-gcc (WinAVR) then the program jumps to _exit() if you ever return from main. I guess other compilers do the same. Solution: add a loop like this one to the end of main():

for(;;);

2) You have enabled the watchdog and end up in an endless loop without re-armoring the watchdog. This will also result in a reset of your CPU.

Thomas

Hi Thomas,

Thanks for that quick response.

I am actually using assembly in writing my program. At the start of the code, I have disabled the watchdog timer and at the end of the main program, i have already appended an infinite loop. But , still, it sleeps, wakes up, and resets after a run.

By the way, i am using JTAGICE mkII in uploading my code to the MCU.

Do I have to still set something for it not to reset?

-Sherwin

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

So I suppose you have the sleep instruction inside the endless loop?
Your program wakes up from sleep mode if you have interrupts enabled. This is part of the problem, but not the root of it: even if your chip wakes up, it will go to sleep again when it executes the sleep instruction in the loop again.

Can you find out which event wakes the AVR up? Do you have possibly any interrupts enabled without defining a handler for it?
Or another thought: could it be the brown-out controller?

pycrc -- a free CRC calculator and C source code generator

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

Actually, I did not use any sleep instruction. At the beginning of the code, I have also cleared the global interrupt enable flag.

It really makes me wonder why does the MCU enter the sleep mode and wake up by itself.

Is it because of the infinite loop at the end of the code? Or is it possibly because of the JTAG interface?

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

I don't think the JTAG interface has anything to do with the reset.

But how can you tell the AVR is entering in sleep mode? What are you monitoring to come to this conclusion? I just want to make sure we are talking about the same thing when we write the word "sleep".

It would help if you describe exactly what you do, what you expect to happen and how the AVR behaves differently.

I'd suggest you write a minimal program that shows the wrong behaviour and post it in this thread.

pycrc -- a free CRC calculator and C source code generator