stm32duino/STM32LowPower

Serial port

Closed this issue · 2 comments

I have been trying to test the low power along with the serial ports.
I am using the Generic STM32WL series board "Generic WLE5CCUx"
My program is this:

#include "STM32LowPower.h"

String command = "Hello";

void setup() {
  Serial.begin(2400);
  Serial1.begin(2400);
  LowPower.begin();
}

void loop() {
  readMeter();
  delay(500);
  LowPower.deepSleep(10 * 1000);
}

void readMeter()
{  
  Serial1.print(command);
  while(Serial1.available()> 0) 
  {
    Serial.println(Serial1.read());
  }
}

I was trying to test it with this code but it only sends the "Hello" command the second time and that's it. If I remove the low power it works correctly.
How can I make the command "Hello" that I set continue to be sent?

fpistm commented

Hi @Lizethgm
Where Serial1 is defined or how?

fpistm commented

Hi @Lizethgm
I've made a fix in #87 fot WB and tested it fix this issue.
About WL, at the beginning I reproduce your issue but after updating the STLink firmware it works as expected.
About your example, I've modify it to not loose any data, as the default Serial instance is LPUART1, it is better to use it to receive the data as it is available in deepSleep while USART1 not (so I've only invert the usage you made.

#include "STM32LowPower.h"

String command = "Hello";

// Generic WL55JC Serial is by default on LPUART1 PA3/PA2
// Defined second Serial1 using USART1 PB7/PB6
HardwareSerial Serial1(PB7, PB6);

void setup() {
  Serial.begin(2400);
  Serial1.begin(2400);
  LowPower.begin();
}

void loop() {
  readMeter();
  delay(500);
  LowPower.sleep(10*1000);
}

void readMeter()
{  
  Serial.println(command);
  while(Serial.available()> 0) 
  {
    Serial1.printf("%c", Serial.read());
  }
}