Atmega328 sleep mode and SoftwareSerial

Hi, i have a project that i am developing that needs to run on batteries and consume very little power.
The project is a GSM load cell measurer.
Basically, it measures the weight on the load cell, and uses a SIM800L module to tell me the values via SMS.
Everything works fine with that part, but when i added the sleep mode functionality, the communication between the atmega328 and sim800L module stopped working.
It is supposed to go like this:
1.Board turns on, configures sim module, retrieves data from EEPROM memory (phone number to report to, PIN to be able to use the board, phone number of the sim card in the sim module and some other stuff).
2.It checks the counter variable to see if it is supposed to go to sleep.
3.If the counter variable gets to 1000(roughly 50sec without communication), it goes to sleep.
4.It checks the voltage of the battery (lead acid). If it is too low or too high it sends an sms saying that and turns off.
5.It checks serial comms. If anything is available it sets the counter to 0 and sees if anything in the data is of value.
6.If the atmega328 is asleep, and the sim module receives an sms or call it wakes up the atmega328 through an interrupt.
The problem i am having is that when the atmega328 wakes up from sleep, it does not read the data from the sim module. What am i doing wrong?
(The code is too long and i have uploaded the .ino file)

mapp() - the map function but modified to be used with floats. Used to get the voltage of the battery.
dozvola() - used to get the number that has access to some sms commands.
poraka() - used to send sms messages.
proverinapon() - checks the voltage of the battery.
sleepNow() - sets the atmega328 to sleep.
checksleep() - checks the counter variable and determines if the atmega328 should go to sleep.
checkSerial() - checks the hardware and software serial lines

Sim_vaga.ino (9.07 KB)

Before you put the processor to sleep, stop software serial.

ss.end();

When the processor wakes up, start software serial again.

ss.begin(baud).

srnet:
Before you put the processor to sleep, stop software serial.

ss.end();

When the processor wakes up, start software serial again.

ss.begin(baud).

I tried this now, and it doesn't work.
It completely misses the data.(takes too long to start)

It sounds like the 328p isn't waking up when the software UART receives a byte. I don't know if this will work, but I wonder if you can configure a pin change interrupt on PD4 (the RXD pin) to make the 328p wake from sleep mode. Maybe it will wake quickly enough to get the data that way.

EDIT: Maybe not! It looks like SoftwareSerial already uses pin change interrupts!

EDIT2: See Reply #3 in this thread as that may hold a clue.

markd833:
It sounds like the 328p isn't waking up when the software UART receives a byte. I don't know if this will work, but I wonder if you can configure a pin change interrupt on PD4 (the RXD pin) to make the 328p wake from sleep mode. Maybe it will wake quickly enough to get the data that way.

EDIT: Maybe not! It looks like SoftwareSerial already uses pin change interrupts!

EDIT2: See Reply #3 in this thread as that may hold a clue.

I fixed it by doing this:

void sleepNow() {
  Serial.println("Vleguvam vo sleep mode");
  sleeping = true;
  scale.power_down();
  Serial.end();
  digitalWrite(ledpin, HIGH);
  delay(250);
  digitalWrite(ledpin, LOW);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  Serial.begin(115200);
  counter = 0;
  sleeping = false;
}
void checksleep() {
  if (counter > 1200)
    sleepNow();
}

The sleeping boolean is used for another part that is irrelevant to this.
The scale.power_down() is to set the HX711 chip to sleep.
I also found out about the pin change interrupts and decided to try that out and it worked!
If you need to set the atmega328( used on arduino nano, uno and pro mini) you can use this with the LowPower library:

void sleepNow() {
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}

It will wake up from software serial and there is nothing else you need to do.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.