Add TXEN pin control

This commit is contained in:
2026-04-26 13:24:15 +03:00
parent 192a008150
commit c15afa9819
2 changed files with 11 additions and 3 deletions

View File

@@ -102,7 +102,7 @@ extern SPIClass SPI;
sx126x::sx126x() : sx126x::sx126x() :
_spiSettings(16E6, MSBFIRST, SPI_MODE0), _spiSettings(16E6, MSBFIRST, SPI_MODE0),
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN), _busy(LORA_DEFAULT_BUSY_PIN), _rxen(LORA_DEFAULT_RXEN_PIN), _ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN), _busy(LORA_DEFAULT_BUSY_PIN), _rxen(LORA_DEFAULT_RXEN_PIN), _txen(LORA_DEFAULT_TXEN_PIN),
_frequency(0), _frequency(0),
_txp(0), _txp(0),
_sf(0x07), _sf(0x07),
@@ -184,6 +184,7 @@ uint8_t ISR_VECT sx126x::singleTransfer(uint8_t opcode, uint16_t address, uint8_
void sx126x::rxAntEnable() { void sx126x::rxAntEnable() {
if (_rxen != -1) { digitalWrite(_rxen, HIGH); } if (_rxen != -1) { digitalWrite(_rxen, HIGH); }
if (_txen != -1) { digitalWrite(_txen, LOW); }
} }
void sx126x::loraMode() { void sx126x::loraMode() {
@@ -316,6 +317,8 @@ int sx126x::begin(long frequency) {
if (_busy != -1) { pinMode(_busy, INPUT); } if (_busy != -1) { pinMode(_busy, INPUT); }
if (!_preinit_done) { if (!preInit()) { return false; } } if (!_preinit_done) { if (!preInit()) { return false; } }
if (_rxen != -1) { pinMode(_rxen, OUTPUT); } if (_rxen != -1) { pinMode(_rxen, OUTPUT); }
if (_txen != -1) { pinMode(_txen, OUTPUT); }
calibrate(); calibrate();
calibrate_image(frequency); calibrate_image(frequency);
@@ -387,6 +390,7 @@ int sx126x::beginPacket(int implicitHeader) {
// radio is powered up. // radio is powered up.
#endif #endif
#endif #endif
if (_txen != -1) { digitalWrite(_txen, HIGH); } //Set TXen high when transmitting
standby(); standby();
if (implicitHeader) { implicitHeaderMode(); } if (implicitHeader) { implicitHeaderMode(); }
@@ -401,6 +405,8 @@ int sx126x::beginPacket(int implicitHeader) {
int sx126x::endPacket() { int sx126x::endPacket() {
setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode); setPacketParams(_preambleLength, _implicitHeaderMode, _payloadLength, _crcMode);
if (_rxen != -1) { digitalWrite(_rxen, LOW); } //Set RXen low when transmitting
uint8_t timeout[3] = {0}; // Put in single TX mode uint8_t timeout[3] = {0}; // Put in single TX mode
executeOpcode(OP_TX_6X, timeout, 3); executeOpcode(OP_TX_6X, timeout, 3);
@@ -772,12 +778,13 @@ void sx126x::setSyncWord(uint16_t sw) {
writeRegister(REG_SYNC_WORD_LSB_6X, 0x24); writeRegister(REG_SYNC_WORD_LSB_6X, 0x24);
} }
void sx126x::setPins(int ss, int reset, int dio0, int busy, int rxen) { void sx126x::setPins(int ss, int reset, int dio0, int busy, int rxen, int txen) {
_ss = ss; _ss = ss;
_reset = reset; _reset = reset;
_dio0 = dio0; _dio0 = dio0;
_busy = busy; _busy = busy;
_rxen = rxen; _rxen = rxen;
_txen = txen;
} }
void sx126x::dumpRegisters(Stream& out) { void sx126x::dumpRegisters(Stream& out) {

View File

@@ -92,7 +92,7 @@ public:
byte random(); byte random();
void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN, int busy = LORA_DEFAULT_BUSY_PIN, int rxen = LORA_DEFAULT_RXEN_PIN); void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN, int busy = LORA_DEFAULT_BUSY_PIN, int rxen = LORA_DEFAULT_RXEN_PIN, int txen = LORA_DEFAULT_TXEN_PIN);
void setSPIFrequency(uint32_t frequency); void setSPIFrequency(uint32_t frequency);
void dumpRegisters(Stream& out); void dumpRegisters(Stream& out);
@@ -125,6 +125,7 @@ private:
int _reset; int _reset;
int _dio0; int _dio0;
int _rxen; int _rxen;
int _txen;
int _busy; int _busy;
long _frequency; long _frequency;
int _txp; int _txp;