What I want to do: I want my ATTiny814 to sleep for 30 secs, wake up and blink an LED. Then go this in a loop.
What problem I am facing: ATTiny814 is not going into power down sleep mode.
I am saying this because it’s consuming 40uA in power down sleep mode and the datasheet says 2-4uA.
Also, when I change the sleep mode to standby sleep mode it consumes the same amount of current i.e. 40uA.
So I am anticipating that ATTiny814 is going into standby sleepmode in both cases.
What extra step am I missing to set the ATTiny814 in power down sleep mode?
My code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include “timers.h”
#include <util/delay.h>
#include <Arduino.h>void RTC_init(void);
void LED0_init(void);
inline void LED0_toggle(void);
void SLPCTRL_init(void);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*/ RTC.PITINTCTRL = RTC_PI_bm; /* Periodic Interrupt: enabled */ RTC.PITCTRLA = (RTC_PERIOD_CYC32768_gc) /* RTC Clock Cycles 32768 */ | (RTC_PITEN_bm) | (RTC_RUNSTDBY_bm); /* Enable: enabled */
}
void LED0_init(void)
{
/* Make High (OFF) /
PORTB.OUT |= PIN1_bm;
/ Make output */
PORTB.DIR |= PIN1_bm;
}
//added for git commitISR(RTC_PIT_vect)
{
/* Clear flag by writing ‘1’: */
RTC.PITINTFLAGS = RTC_PI_bm;PORTB.OUTTGL |= PIN1_bm; _delay_ms(5000); PORTB.OUTTGL |= PIN1_bm;
}
void SLPCTRL_init(void)
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
cli();
}int main(void)
{for (uint8_t pin=7; pin<=1; pin--) (&PORTA.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; PORTB.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc; PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; PORTB.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc; LED0_init(); //SLPCTRL_init(); RTC_init(); /* Enable Global Interrupts */ sei(); while (1) { //SLPCTRL_CTRLA = 0x05; set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sleep_cpu(); sleep_disable(); }
}
Platformio.ini file
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
[platformio]
; Default build target
default_envs = Upload_UPDI
; Parameters used for all environments
[env]
platform = atmelmegaavr
framework = arduino
; Chip in use
board = ATtiny814
; Clock frequency in [Hz]
board_build.f_cpu = 5000000L
; Oscillator type (internal or external)
board_hardware.oscillator = internal
; Unflag build flags
build_unflags =
; Extra build flags
build_flags =
; Monitor port is auto detected. Override here
;monitor_port =
; Serial monitor baud rate
monitor_speed = 115200
; Run the following command to upload with this environment
; pio run -e Upload_UPDI -t upload
[env:Upload_UPDI]
; Upload protocol for UPDI upload
upload_protocol = jtag2updi
;upload_protocol = STK500v1 ;upload protocol changed to STK500v1 as per chatgpt
upload_port = COM8
upload_flags =
upload_speed = 115200
; run the following command to set fuses
; pio run -t fuses -e set_fuses
[env:set_fuses]
; Upload protocol for used to set fuses
upload_protocol = ${env:Upload_UPDI.upload_protocol}
upload_flags =
; Hardware settings
board_hardware.bod = 2.7v
board_hardware.eesave = yes
board_hardware.updipin = updi