From 5ceb014d1bbaf10e2a78d81dcea57aead542494e Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 12 Jun 2021 02:00:54 +0200 Subject: [PATCH] Disable RS485 driver and systick before deep sleep - The RS485 driver consumes about 150 mW if enabled - The systick somehow can wake up the CPU from stop mode --- src/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 49e5e39..e0bf945 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include "measurement.h" #include "deepsleep.h" +#include "pinout.h" #include "config.h" volatile int wait_frame = 1; @@ -223,8 +224,13 @@ int main(void) } else { // charge control already idle if((timebase_ms - charge_control_idle_since) > DEEPSLEEP_DELAY) { - rs485_enqueue("PWR:DEEPSLEEP:ENTRY\n"); + systick_counter_disable(); + // force the RS485 driver into receive mode. The RS485 + // driver alone consumes 150 mW if enabled. + gpio_clear(RS485_PORT, RS485_DE_PIN); deepsleep(DEEPSLEEP_DURATION); + gpio_set(RS485_PORT, RS485_DE_PIN); + systick_counter_enable(); rs485_enqueue("PWR:DEEPSLEEP:EXIT\n"); charge_control_was_idle = false; }