ESP32 S3 with SX1262: Ping Pong with light sleep not working #1522
-
Hi all. using two LilyGO T3 S3s I'm fiddling around with a Ping / Pong between the two boards. Using the following code without lightsleep, every works as expected. However, using light sleep like in this code, the ESP wakes up because of the IRQ for the first ping, starts transmitting the pong, but never gets the IRQ stating the transmit finished. If I use blocking transmit of the pong, again, everything works as expected. #include <RadioLib.h>
#include "config.h"
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
static volatile bool dio1Flag;
static volatile bool isRXFlag;
static String payload = "0";
static int transmissionState = RADIOLIB_ERR_NONE;
static bool gotoSleep = false;
ICACHE_RAM_ATTR void setFlag(void)
{
gpio_pin_wakeup_disable();
dio1Flag = true;
gotoSleep = false;
}
void startReceive()
{
Serial.print(F("Radio listening for ping: "));
isRXFlag = true;
dio1Flag = false;
int state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE)
Serial.println(F("success"));
else
{
Serial.print(F("failed, code "));
Serial.println(state);
}
gotoSleep = true;
}
void setup()
{
Serial.begin(115200);
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
delay(1500);
int state = radio.begin(CONFIG_RADIO_FREQ,
CONFIG_RADIO_BW,
CONFIG_RADIO_SF,
CONFIG_RADIO_CR,
CONFIG_RADIO_SW,
CONFIG_RADIO_OUTPUT_POWER,
CONFIG_RADIO_PL);
Serial.print(F("Radio Initializing ... "));
if (state == RADIOLIB_ERR_NONE)
Serial.println(F("success"));
else
{
Serial.print(F("failed, code "));
Serial.println(state);
while (true)
;
}
radio.setDio1Action(setFlag);
startReceive();
}
void loop()
{
int state;
if (gotoSleep)
{
gotoSleep = false;
gpio_wakeup_enable(RADIO_DIO1_PIN, GPIO_INTR_HIGH_LEVEL);
esp_sleep_enable_gpio_wakeup();
esp_light_sleep_start();
return;
}
if (dio1Flag)
{
// Got an IRQ
dio1Flag = false;
if (isRXFlag)
{
// Got a RX_done IRQ
isRXFlag = false;
state = radio.readData(payload);
Serial.println(F("Radio received ping: "));
if (state == RADIOLIB_ERR_NONE)
{
Serial.print(F("\tData\t"));
Serial.println(payload);
Serial.print(F("Radio sending pong: "));
// Start transmittinng the pong
transmissionState = radio.startTransmit(payload);
}
else
{
Serial.print(F("\tfailed, code "));
Serial.println(state);
startReceive();
}
}
else
{
// Got a TX_done IRQ
if (transmissionState == RADIOLIB_ERR_NONE)
Serial.println(F("finished"));
else
{
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// Pong sent, start receiving again
startReceive();
}
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I don't have much experience with ESP32 sleep modes, so it's hard to tell. Though are two things in the code that are a bit odd:
|
Beta Was this translation helpful? Give feedback.
Then it might worth calling
radio.clearDio1Action();
andradio.setDio1Action(setFlag);
again after the wakeup.