Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idle() function doesnt seem to restore UART/Serial when using USART0_OFF #100

Open
tjko opened this issue May 23, 2020 · 2 comments
Open

Comments

@tjko
Copy link

tjko commented May 23, 2020

If using UART/Serial port it works fine until first call to idle() after that serial is not working (it's sending just garbage). It would seem like UART settings get lost duing low power state and it doesn't get restored after resuming?

Also, similar to issue #36
if calling with "USART0_ON", serial port does not get messed up, but similar to using "TIMER0_ON" call to idle() will return within a millisecond (SLEEP_x) option doesn't work...

@AnnyCaroline
Copy link

I'm also having this problem. But, for me, even using USART0_ON, the behavior is not as expected. The messages are displayed on the serial, but very quickly. In the example below, the LED connected to pin 13 also switches very quickly, not respecting the 4s.

#include "LowPower.h"

void setup() {
  Serial.begin(9600);
  Serial.println("BEGIN");

  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  LowPower.idle(SLEEP_4S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_ON, TWI_OFF);

  Serial.println("4s - ON");
  digitalWrite(13,HIGH);

  LowPower.idle(SLEEP_4S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_ON, TWI_OFF);

  Serial.println("4s - OFF");
  digitalWrite(13,LOW);
}

Before starting to use Serial.println, the LED was blinking at the correct interval.

@eddyp
Copy link

eddyp commented Jul 29, 2021

@AnnyCaroline I think the issue which you're seeing is because the Serial is actually itself generating interrupts, so the sleep cycles are stopped prematurely.

I saw this @rocketscream library doesn't have the latest versioned release in Ardiuino IDE, so I switched to @LowPowerLab's fork which seems to merge all changes from this repo and some fixes, plus is maintained.

Ironically the latest code here has a fix for the correct restauration of timer2, part of 1.81/1.8.1, but the latest release in Arduino IDE is 1.60/1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants