Hi,
I would like to ask what would be the consequences of using the routine of entering in very low power sleep for AVR uProc:
"
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
"
directly from a thread(task) body under ChibiOS with Arduino ?
The goal is to put the MCU on a very low power sleep on a longer period of time (30 minutes) and an external RTC will wake it up via an external interrupt.
If there are consequences what would be a good option to achieve this ?
Thank you.
AVR Power Down Mode with Arduino
Moderator: tfAteba
Re: AVR Power Down Mode with Arduino
I just tried it out now and had no problem sleeping and waking up (using INT0 to wake up). You just have to do some synchronization if you don't want to sleep while doing something else. The code below, for example, can go to sleep while sending data to the serial port and finishes when coming back.
Code: Select all
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <avr/sleep.h>
CH_IRQ_HANDLER(INT0_vect) {
CH_IRQ_PROLOGUE();
sleep_disable();
CH_IRQ_EPILOGUE();
}
static WORKING_AREA(waThread1, 32);
static msg_t Thread1(void *arg) {
while (TRUE) {
palTogglePad(IOPORT2, PORTB_LED1);
chThdSleepMilliseconds(1000);
}
return 0;
}
static WORKING_AREA(waThread2, 32);
static msg_t Thread2(void *arg) {
while (TRUE) {
sdWrite(&SD1, "Run\r\n", 5);
chThdSleepMilliseconds(2000);
}
return 0;
}
int main(void) {
halInit();
chSysInit();
/* INT0 configuration */
EICRA |= _BV(ISC00);
EICRA &= ~_BV(ISC01); /* Any edge interrupt */
EIFR |= _BV(INTF0); /* Clear interrupt */
EIMSK |= _BV(INT0); /* Enable */
/* Configure power-down sleep */
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
palClearPad(IOPORT2, PORTB_LED1);
sdStart(&SD1, NULL);
sdWrite(&SD1, "Boot\r\n", 6);
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
while(TRUE) {
chThdSleepMilliseconds(10000);
sleep_enable();
sleep_cpu();
}
}