#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/cpufunc.h>
#include "timers.h"
#include <util/delay.h>
#include <Arduino.h>
#include "avr/sleep.h"
#include "avr/wdt.h"
#include "Wire.h"
void RTC_init(void);
void LED0_init(void);
inline void LED0_toggle(void);
void SLPCTRL_init(void);
//uint8_t wakeup = 0;
volatile uint8_t flash = 0;
void RTC_init(void)
{
/* Initialize RTC: */
while (RTC.STATUS > 0)
{
; /* Wait for all register to be synchronized */
}
/* 32.768kHz External Crystal Oscillator (XOSC32K) */
RTC.CLKSEL = RTC_CLKSEL_INT1K_gc; /*ULP Clock oscillator is being used*/
/* Run in debug: enabled */
RTC.DBGCTRL = RTC_DBGRUN_bm;
RTC.PITINTCTRL = RTC_PI_bm; /* Periodic Interrupt: enabled */
RTC.PITCTRLA = (RTC_PERIOD_CYC32768_gc) /* RTC Clock Cycles 32768 */
| (RTC_PITEN_bm); /* Enable: enabled */
}
void LED0_init(void)
{
/* Make High (OFF) */
PORTB.OUT |= PIN1_bm;
/* Make output */
PORTB.DIR |= PIN1_bm;
}
ISR(RTC_PIT_vect)
{
/* Clear flag by writing '1': */
RTC.PITINTFLAGS = RTC_PI_bm;
flash = 1;
}
void SLPCTRL_init(void)
{
SLPCTRL.CTRLA |= SLPCTRL_SMODE_PDOWN_gc;
SLPCTRL.CTRLA |= SLPCTRL_SEN_bm;
}
int main(void)
{
LED0_init();
RTC_init();
SLPCTRL_init();
//(&PORTA.PIN0CTRL)[0];
for (uint8_t pin=7; pin<=1; pin--)
(&PORTA.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc;
PORTB.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
PORTB.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
/* Enable Global Interrupts */
sei();
while (1)
{
/* Put the CPU in sleep */
sleep_cpu();
if(flash == 1)
{
PORTB.OUTTGL |= PIN1_bm;
_delay_ms(5000);
PORTB.OUTTGL |= PIN1_bm;
}
}
}
ATTiny814 is not going into power down sleep mode. This was working a few days back I haven't changed anything. When it was working the device was consuming 0.6uA in sleep mode and 1.874 mA when green led flashed. After a few days when I flashed the firmware again. The ATTiny814 is now consuming 32uA in sleep mode and 1.872 mA when green led flashes.
I have tried enable the disabling the sleep mode before and after the sleep_cpu instruction. But still no response.
Do comment if you guys have experienced this before.