When calling this right before Setup ends, it works, My circuit goes down from 9mA to 4mA which is ~5mA my Atmega328 needs!
When calling this function in my main, it does not work. My guess it that the sleep gets immediatly interrupted, because if i comment out the "interrupts()" (which does not allow any interrupts) the sleep function does work!
Is there any way how to locate the source of interrupt?
in PWR_DOWN the Mega could only wake up from
INT1/0, TWI, WDT but how can i find out which one is the cause?
INT1/0, TWI, WDT but how can i find out which one is the cause?
To be sure, install ISRs for all possible causes and set a boolean value accordingly (must be declared volatile!) which you can check then in the main loop.
INT1/0, TWI, WDT but how can i find out which one is the cause?
That's the list for the ATmega328p, the ATmega2560 additionally wakes up if INT2/3 is fired or a LEVEL interrupt on INT4-7 occurred. But these interrupts must be configured.
Most probably you didn't include the necessary headers to get SLEEP_MODE_PWR_DOWN defined. Then the mode is set to SLEEP_MODE_IDLE which wakes up from the timer call that the Arduino framework does to make the millis() call available. As you didn't post complete code we cannot check for that.