Page 1 of 1
ATinny85 Sleep Flowcode
Posted: Thu Feb 20, 2025 1:28 am
by Matrixv8
Hi everyone, I have been trying to write a code to put ATtiny85 to sleep but with no success. I would really appreciate an example in Flowcode 10. I am using USBtiny as a programmer.
Thank you.
Re: ATinny85 Sleep Flowcode
Posted: Thu Feb 20, 2025 6:25 am
by mnfisher
It is possible to do:
In supplementary code:
Then in a code block:
Code: Select all
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Other modes are available - see sleep.h
sleep_enable();
sleep_cpu();
sleep_disable();
You'll also need something to wake up the MCU - for example a pin change interrupt (or wdt interrupt etc)
Martin
Re: ATinny85 Sleep Flowcode
Posted: Thu Feb 20, 2025 5:07 pm
by Matrixv8
Thank you for your help.
Re: ATinny85 Sleep Flowcode
Posted: Thu Feb 20, 2025 11:20 pm
by Matrixv8
Martin it worked perfectly, the supplementary code was key. Now, I have tried everything to wakeup the ATtiny with INT0 pin7, port B2 with no success. Any idea?
PS: I will keep my questions to a minimum.
Regards,
Pierre
Re: ATinny85 Sleep Flowcode
Posted: Fri Feb 21, 2025 8:03 am
by mnfisher
Hi Pierre,
Can you post your code.
I'm not at a computer at the moment but something like:
Code: Select all
Enable interrupt
Loop
Sleep
Do something
End loop
The interrupt macro needs to be short - it doesn't need to do anything (it could be an empty macro) or it could increment a 'wake' counter.
If you are using a rising edge interrupt — the pin needs to be pulled to ground (with a resistor either internal pull-down or external) and if you are using a button watch out for bounce (which might give multiple wakes per press)
Falling edge interrupt needs internal pull up or resistor to VCC
Martin
Re: ATinny85 Sleep Flowcode
Posted: Fri Feb 21, 2025 11:49 pm
by Matrixv8
Hi Martin, thank you for your help. Attached is my Flowcode. I use a 10K pull up resistor on port B2. I use a digital high low output, so no switch noise. I send a high to low pulse. The INT micro works until the chip goes to sleep then I can not wake the chip unless I reset it.
Thank you for you help.
Pierre
Re: ATinny85 Sleep Flowcode
Posted: Sat Feb 22, 2025 7:29 am
by mnfisher
The 'sleep' is outside of your loop, so it when the MCU 'wakes' it will be just 'fall off the end of the program' - this actually just has a while(1) ; loop - NOT a reset. So move the sleep into the loop and it should work as expected (or add a 'reset' after it?)
I also forgot to mention - if using a separate device for waking then ground must be common.
Martin
Re: ATinny85 Sleep Flowcode
Posted: Sun Feb 23, 2025 12:28 am
by Matrixv8
Hi Martin, moving the C code in the loop was the first fix to my problem, It would go to sleep but not wake up. I found that the INT0 on Attiny85 with Flowcode 10 was not waking up the micro. I had to use the IOC PortB2 and click on the Port B2 pin 7 of the chip icon inside the Inerrupt command icon for it to work. So both fix created a solution. I am attaching an example for the readers hopping that it will help them as I spent a long time to figure it out.
Again a great thanks for your quick help.
Pierre
Re: ATinny85 Sleep Flowcode
Posted: Sun Feb 23, 2025 10:03 am
by mnfisher
Thanks - glad you got it working...
Martin