So I recently got a full duplex transceiver(ebyte e34-2g4d20d) but the manufacturer seem to not have an active library available for this specific device however, they do have libraries for it earlier half duplex variants. So my team and I decided to work on a library for it using it's datasheet(link to datasheet ) and libraries for it's earlier half duplex variant. we were able to get the device work with the library in half duplex mode but we are having a bit of a challenge making the device work in full duplex mode.
as per the datasheet, we have been able to set the device to full duplex mode using ESP-32, we have further tried to utilize the core feature of the esp32 by assigning Tx function of the library to execute on core 0 of and Rx to core 1 of esp32. however, when we upload and test the library and implementation code on esp 32, we observe that the transmission and reception process happening on both cores of the esp32 aren't concurrent, they seem to be interfering with each other as tx seemed to halt for rx operation and vice versa.
please note that we decided to utilize the dual core feature of the esp32 because we expect that it would be the best way to implement the utilization of a full duplex radio.
below is my code implementing the library:
#include "EBYTEZyeconnect.h"
#define PIN_RX 16 // Serial2 RX (connect this to the EBYTE Tx pin)
#define PIN_TX 17 // Serial2 TX pin (connect this to the EBYTE Rx pin)
#define PIN_M0 19 // D19 on the board (possibly pin 19)
#define PIN_M1 18 // D18 on the board (possibly called pin 18)
#define PIN_AX 5 // D5 on the board (possibly called pin 5)
// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules
struct DATA {
unsigned long Count;
int Bits;
float Volts;
float Amps;
};
// these are just dummy variables, replace with your own
int Chan;
DATA MyData;
unsigned long Last;
// create the transceiver object, passing in the serial and pins
EBYTEZyeconnect Transceiver(&Serial2, PIN_M0, PIN_M1, PIN_AX);
int count=0;
void send() {
// measure some data and save to the structure
MyData.Count++;
MyData.Bits = analogRead(A0);
MyData.Volts = 3.33;
//MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );
// i highly suggest you send data using structures and not
// a parsed data--i've always had a hard time getting reliable data using
// a parsing method
Transceiver.SendStruct(&MyData, sizeof(MyData));
// note, you only really need this library to program these EBYTE units
// you can call write directly on the EBYTE Serial object
// Serial2.write((uint8_t*) &Data, PacketSize );
// let the use know something was sent
count++;
Serial.print(count);
Serial.print("===");
Serial.print("Sending: ");
Serial.println(MyData.Count);
delay(8);
}
void receive() {
// if the transceiver serial is available, proces incoming data
// you can also use Transceiver.available()
if (Serial2.available()) {
// i highly suggest you send data using structures and not
// a parsed data--i've always had a hard time getting reliable data using
// a parsing method
Transceiver.GetStruct(&MyData, sizeof(MyData));
// note, you only really need this library to program these EBYTE units
// you can call readBytes directly on the EBYTE Serial object
// Serial2.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));
// dump out what was just received
Serial.print("Count: "); Serial.println(MyData.Count);
Serial.print("Bits: "); Serial.println(MyData.Bits);
Serial.print("Volts: "); Serial.println(MyData.Volts);
// if you got data, update the checker
Last = millis();
}
else {
// if the time checker is over some prescribed amount
// let the user know there is no incoming data
if ((millis() - Last) > 1000) {
Serial.println("Searching: ");
Last = millis();
}
}
}
void codeForTask1( void * parameter ) {
for (;;) {
send();
}
}
void codeForTask2( void * parameter ) {
for (;;) {
receive();
}
}
TaskHandle_t Task1, Task2;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
Transceiver.init();
Transceiver.SetUARTBaudRate(UDR_57600);
Transceiver.SaveParameters(PERMANENT);
Transceiver.PrintParameters();
xTaskCreatePinnedToCore(codeForTask1,"Send",5000,NULL,2,&Task1,0);
//delay(500); // needed to start-up task1
xTaskCreatePinnedToCore(codeForTask2,"Receive",5000,NULL,2,&Task2,1);
}
void loop() {
}
We believe we are having this issue because of the way we designed the library or the way we we implemented it in the esp32. Any push in the right direction, maybe in recommending a full duplex transceiver library written in c would very much help.
Below is the section of our library used to set radio operating mode according to datasheet:
/*
method to set the mode (program, normal, etc.)
*/
void EBYTEZyeconnect::SetMode(uint8_t mode) {
delay(PIN_RECOVER);
if (mode == MODE_1_FULL_DUPLEX) {
digitalWrite(_M0, HIGH);
digitalWrite(_M1, LOW);
}
else if (mode == MODE_0_HALF_DUPLEX) {
digitalWrite(_M0, LOW);
digitalWrite(_M1, LOW);
}
else if (mode == MODE_2_RESERVATION_MODE) {
digitalWrite(_M0, LOW);
digitalWrite(_M1, HIGH);
}
else if (mode == MODE_3_SETTING_MODE) {
digitalWrite(_M0, HIGH);
digitalWrite(_M1, HIGH);
}
delay(PIN_RECOVER);
ClearBuffer();
// wait until aux pin goes back low
CompleteTask(4000);
}