Dear Valued Members,
for some tasks I need small MCUs, and the tinyAVR® 1-Series seems to be quite suitable.
But unexpected a curious occurrence: after going to sleep the pullup is disconnected (detected with a multimeter).
Narrowed code example
(after button pressed und released 5x blink and go to sleep again):
/* ------------------------------------------ ATTINY416-XNANO LED = PB5, active LOW Button = PB4, pressed = GND -------------------------------------------- */ #include <avr/io.h> #define F_CPU 3333333 // 20MHz/6 #include <util/delay.h> #include <avr/interrupt.h> #include <avr/sleep.h> uint8_t count = 0; // cycle count ISR(PORTB_PORT_vect) { PORTB.INTFLAGS = PORT_INT4_bm; // clear the interrupt flag } int main( void ) { PORTB.PIN4CTRL = PORT_PULLUPEN_bm; // PB4 pullup PORTB.OUTSET = PIN5_bm; // PB5 HIGH, LED off PORTB.DIRSET = PIN5_bm; // PB5 as output SLPCTRL.CTRLA = SLPCTRL_SMODE_PDOWN_gc; // select Power-Down sleep mode sei(); // enable global interrupts while(1){ while(!(PORTB.IN & PIN4_bm)) {} // wait while button pressed (LOW) PORTB.OUTCLR = PIN5_bm; // PB5 LOW, LED on _delay_ms(100); PORTB.OUTSET = PIN5_bm; // PB5 HIGH, LED off _delay_ms(400); count++; if(count == 5) { count = 0; PORTB.DIRCLR = PIN5_bm; // PB5 turned input PORTB.PIN4CTRL = PORT_ISC_LEVEL_gc; // LOW level interrupt on PB4 sleep_mode(); PORTB.PIN4CTRL = PORT_ISC_INTDISABLE_gc; // disable interrupt on PB4 PORTB.DIRSET = PIN5_bm; // PB5 turned output } } }
Does anybody have an ATTINY416-XNANO? Please find out my code error.