SX126x-Arduino: Esp32-c3 chip running PingPong does not respond, request help

ESP32-C3 is a cost-effective, RISC-V-based MCU with Wi-Fi and Bluetooth 5 (LE) connectivity for secure IoT applications. The ESP32-C3 is a chip recently released by Espressif

When I run the following code, only the logs in the setup() and loop() methods have any output. The logs in other methods such as OnRxTimeout() have no output. I tried two C3 development boards and two LLCC68 modules.Can you help me see what’s wrong?

#include <Arduino.h>

#include <SX126x-Arduino.h>
#include <SPI.h>

hw_config hwConfig;

// ESP32 - SX126x pin configuration
int PIN_LORA_RESET = 2;  // LORA RESET
int PIN_LORA_DIO_1 = 3; // LORA DIO_1
int PIN_LORA_BUSY = 18;  // LORA SPI BUSY
int PIN_LORA_NSS = SS;	// LORA SPI CS
int PIN_LORA_SCLK = SCK;  // LORA SPI CLK
int PIN_LORA_MISO = MISO;  // LORA SPI MISO
int PIN_LORA_MOSI = MOSI;  // LORA SPI MOSI
int RADIO_TXEN = -1;	 // LORA ANTENNA TX ENABLE
int RADIO_RXEN = -1;	 // LORA ANTENNA RX ENABLE


// Function declarations
void OnTxDone(void);
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
void OnTxTimeout(void);
void OnRxTimeout(void);
void OnRxError(void);
void OnCadDone(bool cadResult);

// Check if the board has an LED port defined

#define LED_BUILTIN 2

// Define LoRa parameters
#define RF_FREQUENCY 868000000  // Hz
#define TX_OUTPUT_POWER 22		// dBm
#define LORA_BANDWIDTH 0		// [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]//比特率LLCC68 越小越慢越远
#define LORA_SPREADING_FACTOR 9 // [SF7..SF12]//扩频因子LLCC68 SF5..SF9 越大越慢越远
#define LORA_CODINGRATE 1		// [1: 4/5, 2: 4/6,  3: 4/7,  4: 4/8]//编码率 越大冗余越多,越慢,越远
#define LORA_PREAMBLE_LENGTH 8  // Same for Tx and Rx //前导码,用于睡眠唤醒
#define LORA_SYMBOL_TIMEOUT 0   // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 3000
#define TX_TIMEOUT_VALUE 3000

#define BUFFER_SIZE 64 // Define the payload size here

static RadioEvents_t RadioEvents;
static uint16_t BufferSize = BUFFER_SIZE;
static uint8_t RcvBuffer[BUFFER_SIZE];
static uint8_t TxdBuffer[BUFFER_SIZE];
static bool isMaster = true;
const uint8_t PingMsg[] = "PING";
const uint8_t PongMsg[] = "PONG";

time_t timeToSend;

time_t cadTime;

uint8_t pingCnt = 0;
uint8_t pongCnt = 0;

void setup()
{
	pinMode(LED_BUILTIN, OUTPUT);
	digitalWrite(LED_BUILTIN, LOW);

	// Define the HW configuration between MCU and SX126x
	hwConfig.CHIP_TYPE = SX1262_CHIP;		  // Example uses an eByte E22 module with an SX1262
	hwConfig.PIN_LORA_RESET = PIN_LORA_RESET; // LORA RESET
	hwConfig.PIN_LORA_NSS = PIN_LORA_NSS;	 // LORA SPI CS
	hwConfig.PIN_LORA_SCLK = PIN_LORA_SCLK;   // LORA SPI CLK
	hwConfig.PIN_LORA_MISO = PIN_LORA_MISO;   // LORA SPI MISO
	hwConfig.PIN_LORA_DIO_1 = PIN_LORA_DIO_1; // LORA DIO_1
	hwConfig.PIN_LORA_BUSY = PIN_LORA_BUSY;   // LORA SPI BUSY
	hwConfig.PIN_LORA_MOSI = PIN_LORA_MOSI;   // LORA SPI MOSI
	hwConfig.RADIO_TXEN = RADIO_TXEN;		  // LORA ANTENNA TX ENABLE
	hwConfig.RADIO_RXEN = RADIO_RXEN;		  // LORA ANTENNA RX ENABLE
	hwConfig.USE_DIO2_ANT_SWITCH = true;	  // Example uses an CircuitRocks Alora RFM1262 which uses DIO2 pins as antenna control
	hwConfig.USE_DIO3_TCXO = true;			  // Example uses an CircuitRocks Alora RFM1262 which uses DIO3 to control oscillator voltage
	hwConfig.USE_DIO3_ANT_SWITCH = false;	 // Only Insight ISP4520 module uses DIO3 as antenna control

	// Initialize Serial for debug output
	Serial.begin(115200);

	Serial.println("=====================================");
	Serial.println("SX126x PingPong test");
	Serial.println("=====================================");

	Serial.println("MCU Espressif ESP32");

	uint8_t deviceId[8];

	BoardGetUniqueId(deviceId);
	Serial.printf("BoardId: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
				  deviceId[7],
				  deviceId[6],
				  deviceId[5],
				  deviceId[4],
				  deviceId[3],
				  deviceId[2],
				  deviceId[1],
				  deviceId[0]);

	// Initialize the LoRa chip
	Serial.println("Starting lora_hardware_init");
	
	lora_hardware_init(hwConfig);
	
	// Initialize the Radio callbacks
	RadioEvents.TxDone = OnTxDone;
	RadioEvents.RxDone = OnRxDone;
	RadioEvents.TxTimeout = OnTxTimeout;
	RadioEvents.RxTimeout = OnRxTimeout;
	RadioEvents.RxError = OnRxError;
	RadioEvents.CadDone = OnCadDone;

	// Initialize the Radio
	Radio.Init(&RadioEvents);
	
	// Set Radio channel
	Radio.SetChannel(RF_FREQUENCY);

	// Set Radio TX configuration
	Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
					  LORA_SPREADING_FACTOR, LORA_CODINGRATE,
					  LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
					  true, 0, 0, LORA_IQ_INVERSION_ON, TX_TIMEOUT_VALUE);

	// Set Radio RX configuration
	Radio.SetRxConfig(MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
					  LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
					  LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
					  0, true, 0, 0, LORA_IQ_INVERSION_ON, true);
	//return;
	// Start LoRa
	Serial.println("Starting Radio.Rx");
	Radio.Rx(RX_TIMEOUT_VALUE);

	timeToSend = millis();
}

uint16_t mCounter =0;
void loop() {
	vTaskDelay(3000);
	Serial.print(String("loop:")+mCounter);
	mCounter++;
}

/**@brief Function to be executed on Radio Tx Done event
 */
void OnTxDone(void){
	Serial.println("OnTxDone");
	Radio.Rx(RX_TIMEOUT_VALUE);
}

void startCAD(){
	// Check if our channel is available for sending
	Radio.Standby();
	Radio.SetCadParams(LORA_CAD_08_SYMBOL, LORA_SPREADING_FACTOR + 13, 10, LORA_CAD_ONLY, 0);
	cadTime = millis();
	Radio.StartCad();
}

/**@brief Function to be executed on Radio Rx Done event
 */
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr){
	Serial.println("OnRxDone");
	vTaskDelay(10);
	BufferSize = size;
	memcpy(RcvBuffer, payload, BufferSize);

	Serial.printf("RssiValue=%d dBm, SnrValue=%d\n", rssi, snr);

	for (int idx = 0; idx < size; idx++){
		Serial.printf("%02X ", RcvBuffer[idx]);
	}
	Serial.println("");

	digitalWrite(LED_BUILTIN, HIGH);

	if (isMaster == true) {
		if (BufferSize > 0) {
			if (strncmp((const char *)RcvBuffer, (const char *)PongMsg, 4) == 0) {
				Serial.println("Received a PONG in OnRxDone as Master");
				// Wait 500ms before sending the next package
				vTaskDelay(500);
				startCAD();
			}
			else if (strncmp((const char *)RcvBuffer, (const char *)PingMsg, 4) == 0) { 
				// A master already exists then become a slave
				Serial.println("Received a PING in OnRxDone as Master");
				isMaster = false;
				Radio.Rx(RX_TIMEOUT_VALUE);
			}
			else // valid reception but neither a PING or a PONG message
			{	// Set device as master and start again
				isMaster = true;
				Radio.Rx(RX_TIMEOUT_VALUE);
			}
		}
	}
	else {
		if (BufferSize > 0) {
			if (strncmp((const char *)RcvBuffer, (const char *)PingMsg, 4) == 0) {
				Serial.println("Received a PING in OnRxDone as Slave"); 
				startCAD();
			}
			else // valid reception but not a PING as expected
			{	// Set device as master and start again
				Serial.println("Received something in OnRxDone as Slave");
				isMaster = true;
				Radio.Rx(RX_TIMEOUT_VALUE);
			}
		}
	}
}

/**@brief Function to be executed on Radio Tx Timeout event
 */
void OnTxTimeout(void) {
	// Radio.Sleep();
	Serial.println("OnTxTimeout");
	digitalWrite(LED_BUILTIN, LOW);
	Radio.Rx(RX_TIMEOUT_VALUE);
}

/**@brief Function to be executed on Radio Rx Timeout event
 */
void OnRxTimeout(void) {
	Serial.println("OnRxTimeout");
	digitalWrite(LED_BUILTIN, LOW);

	if (isMaster == true) {
		// Wait 500ms before sending the next package
		vTaskDelay(500);
		startCAD();
	}
	else {
		// No Ping received within timeout, switch to Master
		isMaster = true;
		startCAD();
	}
}

/**@brief Function to be executed on Radio Rx Error event
 */
void OnRxError(void){
	Serial.println("OnRxError");
	digitalWrite(LED_BUILTIN, LOW);

	if (isMaster == true) {
		// Wait 500ms before sending the next package
		vTaskDelay(500); 
		startCAD();
	}
	else {
		Radio.Rx(RX_TIMEOUT_VALUE);
	}
}

/**@brief Function to be executed on Radio Rx Error event
 */
void OnCadDone(bool cadResult) {
	time_t duration = millis() - cadTime;
	if (cadResult) {
		Serial.printf("CAD returned channel busy after %ldms\n", duration);
		Radio.Rx(RX_TIMEOUT_VALUE);
	}
	else {
		Serial.printf("CAD returned channel free after %ldms\n", duration);
		if (isMaster) {
			Serial.println("Sending a PING in OnCadDone as Master");
			// Send the next PING frame
			TxdBuffer[0] = 'P';
			TxdBuffer[1] = 'I';
			TxdBuffer[2] = 'N';
			TxdBuffer[3] = 'G';
		}
		else {
			Serial.println("Sending a PONG in OnCadDone as Slave");
			// Send the reply to the PONG string
			TxdBuffer[0] = 'P';
			TxdBuffer[1] = 'O';
			TxdBuffer[2] = 'N';
			TxdBuffer[3] = 'G';
		}
		// We fill the buffer with numbers for the payload
		for (int i = 4; i < BufferSize; i++) {
			TxdBuffer[i] = i - 4;
		}
		Radio.Send(TxdBuffer, BufferSize);
	}
}

log:


[18:50:04.149]收←◆loop:808
[18:50:07.249]收←◆ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xd (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1428
load:0x403ce000,len:0xc04
load:0x403d0000,len:0x292c
SHA-256 comparison failed:
Calculated: 9f7363434bc7a1a2434ba3062500fa10b9fce5bb859899ee0424321b4ddaf742
Expected: 9b18b42e3e8e407f5e7b13f26c80172eda36d674c584e818f50843c766ebde69
Attempting to boot anyway...
entry 0x403ce000
I (48) boot: ESP-IDF v4.4-dev-2313-gc69f0ec32 2nd stage bootloader
I (49) boot: compile time 12:10:14
I (49) boot: chip revision: 3
I (49) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (55) qio_mode: Enabling default flash chip QIO
I (59) boot.esp32c3: SPI Speed      : 80MHz
I (63) boot.esp32c3: SPI Mode       : QIO
I (67) boot.esp32c3: SPI Flash Size : 4MB
I (71) boot: Enabling RNG early entropy source...
I (75) boot: Partition Table:
I (78) boot: ## Label            Usage          Type ST Offset   Length
I (84) boot:  0 nvs              WiFi data        01 02 00009000 00005000
I (91) boot:  1 otadata          OTA data         01 00 0000e000 00002000
I (97) boot:  2 app0             OTA app          00 10 00010000 00140000
I (104) boot:  3 app1             OTA app          00 11 00150000 00140000
I (110) boot:  4 spiffs           Unknown data     01 82 00290000 00170000
I (117) boot: End of partition table
I (120) boot_comm: chip revision: 3, min. application chip revision: 0
I (126) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=08350h ( 33616) map
I (139) esp_image: segment 1: paddr=00018378 vaddr=3fc8a800 size=014dch (  5340) load
I (142) esp_image: segment 2: paddr=0001985c vaddr=40380000 size=067bch ( 26556) load
I (153) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=25570h (152944) map
I (178) esp_image: segment 4: paddr=00045598 vaddr=403867bc size=03ff4h ( 16372) load
I (181) esp_image: segment 5: paddr=00049594 vaddr=50000000 size=00010h (    16) load
I (185) boot: Loaded app from partition at offset 0x10000
I (187) boot: Disabling RNG early entropy source...
=====================================
SX126x PingPong test
=====================================
MCU Espressif ESP32
BoardId: 00-00-E8-1A-C2-A1-DF-7C
Starting lora_hardware_init

[18:50:07.527]收←◆Starting Radio.Rx

[18:50:10.524]收←◆loop:0
[18:50:13.529]收←◆loop:1
[18:50:16.534]收←◆loop:2
[18:50:19.539]收←◆loop:3
[18:50:22.544]收←◆loop:4
[18:50:25.549]收←◆loop:5
[18:50:28.553]收←◆loop:6
[18:50:31.585]收←◆loop:7
[18:50:34.563]收←◆loop:8
[18:50:37.568]收←◆loop:9
[18:50:40.574]收←◆loop:10
[18:50:43.579]收←◆loop:11
[18:50:46.584]收←◆loop:12
[18:50:49.589]收←◆loop:13
[18:50:52.594]收←◆loop:14
[18:50:55.598]收←◆loop:15
[18:50:58.604]收←◆loop:16

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@valioiv I have no plans to add support for LLCC68. I do not have this LoRa transceiver and cannot test anything.

You are welcome to submit a pull request if you can get it to work.

@valioiv I am using the “RadioLib” library and can communicate normally. Later, I found that my LLCC68 module adapted to the frequency band of 410MHz~525MHz, which was 868MHZ in the current test with the “SX126X-Arduino” library. Maybe this problem caused the communication failure, I did not continue the test