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.
ATinny85 Sleep Flowcode
-
- Posts: 10
- http://meble-kuchenne.info.pl
- Joined: Mon Jun 03, 2024 2:51 am
- Been thanked: 3 times
-
- Valued Contributor
- Posts: 1547
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 138 times
- Been thanked: 737 times
Re: ATinny85 Sleep Flowcode
It is possible to do:
In supplementary code:
Then in a code block:
You'll also need something to wake up the MCU - for example a pin change interrupt (or wdt interrupt etc)
Martin
In supplementary code:
Code: Select all
#include <avr/sleep.h>
Code: Select all
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Other modes are available - see sleep.h
sleep_enable();
sleep_cpu();
sleep_disable();
Martin
Re: ATinny85 Sleep Flowcode
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
PS: I will keep my questions to a minimum.
Regards,
Pierre
-
- Valued Contributor
- Posts: 1547
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 138 times
- Been thanked: 737 times
Re: ATinny85 Sleep Flowcode
Hi Pierre,
Can you post your code.
I'm not at a computer at the moment but something like:
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
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
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
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
Thank you for you help.
Pierre
- Attachments
-
- Attiny85 Test.fcfx
- Feb 25, 20025
- (9.96 KiB) Downloaded 25 times
-
- Valued Contributor
- Posts: 1547
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 138 times
- Been thanked: 737 times
Re: ATinny85 Sleep Flowcode
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
I also forgot to mention - if using a separate device for waking then ground must be common.
Martin
Re: ATinny85 Sleep Flowcode
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
Again a great thanks for your quick help.
Pierre
- Attachments
-
- Attiny85 Sleep And Wake Up Working Example Code.fcfx
- ATtiny85 Sleep And Wake Up Working Example Code
- (10.3 KiB) Downloaded 24 times