Merge branch 'master' of https://github.com/jgromes/RadioLib
* 'master' of https://github.com/jgromes/RadioLib: Fixed keyword separator Fixed SoftwareSerial for ESP8266 core 2.6.0 [SX126x] Moved debug output out of SPI transaction
This commit is contained in:
commit
36979d81ec
4 changed files with 77 additions and 31 deletions
|
@ -88,8 +88,8 @@ setDataShaping KEYWORD2
|
||||||
setOOK KEYWORD2
|
setOOK KEYWORD2
|
||||||
setDataShapingOOK KEYWORD2
|
setDataShapingOOK KEYWORD2
|
||||||
setCRC KEYWORD2
|
setCRC KEYWORD2
|
||||||
variablePacketLengthMode KEYWORD2
|
variablePacketLengthMode KEYWORD2
|
||||||
fixedPacketLengthMode KEYWORD2
|
fixedPacketLengthMode KEYWORD2
|
||||||
|
|
||||||
# RF69-specific
|
# RF69-specific
|
||||||
setAESKey KEYWORD2
|
setAESKey KEYWORD2
|
||||||
|
|
|
@ -5,7 +5,11 @@ ISerial::ISerial(Module* mod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISerial::begin(long speed) {
|
void ISerial::begin(long speed) {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
_mod->ModuleSerial->begin(speed, _mod->getRx(), _mod->getTx(), SWSERIAL_8N1);
|
||||||
|
#else
|
||||||
_mod->ModuleSerial->begin(speed);
|
_mod->ModuleSerial->begin(speed);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ISerial::listen() {
|
bool ISerial::listen() {
|
||||||
|
|
|
@ -9,6 +9,9 @@ Module::Module(int rx, int tx, HardwareSerial* useSer) {
|
||||||
|
|
||||||
#ifdef SOFTWARE_SERIAL_UNSUPPORTED
|
#ifdef SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
ModuleSerial = useSer;
|
ModuleSerial = useSer;
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
ModuleSerial = new SoftwareSerial();
|
||||||
|
(void)useSer;
|
||||||
#else
|
#else
|
||||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||||
(void)useSer;
|
(void)useSer;
|
||||||
|
@ -36,6 +39,9 @@ Module::Module(int cs, int int0, int int1, int rx, int tx, SPIClass& spi, SPISet
|
||||||
|
|
||||||
#ifdef SOFTWARE_SERIAL_UNSUPPORTED
|
#ifdef SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
ModuleSerial = useSer;
|
ModuleSerial = useSer;
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
ModuleSerial = new SoftwareSerial();
|
||||||
|
(void)useSer;
|
||||||
#else
|
#else
|
||||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||||
(void)useSer;
|
(void)useSer;
|
||||||
|
@ -63,6 +69,8 @@ void Module::init(uint8_t interface, uint8_t gpio) {
|
||||||
case USE_UART:
|
case USE_UART:
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
ModuleSerial->begin(baudrate, SERIAL_8N1, _rx, _tx);
|
ModuleSerial->begin(baudrate, SERIAL_8N1, _rx, _tx);
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
ModuleSerial->begin(baudrate, _rx, _tx, SWSERIAL_8N1);
|
||||||
#else
|
#else
|
||||||
ModuleSerial->begin(baudrate);
|
ModuleSerial->begin(baudrate);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1280,7 +1280,12 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
SPIClass* spi = _mod->getSpi();
|
SPIClass* spi = _mod->getSpi();
|
||||||
SPISettings spiSettings = _mod->getSpiSettings();
|
SPISettings spiSettings = _mod->getSpiSettings();
|
||||||
|
|
||||||
|
#ifdef RADIOLIB_VERBOSE
|
||||||
|
uint8_t debugBuff[256];
|
||||||
|
#endif
|
||||||
|
|
||||||
// ensure BUSY is low (state meachine ready)
|
// ensure BUSY is low (state meachine ready)
|
||||||
|
RADIOLIB_VERBOSE_PRINTLN(F("Wait for BUSY ... "));
|
||||||
uint32_t start = millis();
|
uint32_t start = millis();
|
||||||
while(digitalRead(_mod->getRx())) {
|
while(digitalRead(_mod->getRx())) {
|
||||||
if(millis() - start >= timeout) {
|
if(millis() - start >= timeout) {
|
||||||
|
@ -1293,66 +1298,54 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
spi->beginTransaction(spiSettings);
|
spi->beginTransaction(spiSettings);
|
||||||
|
|
||||||
// send command byte(s)
|
// send command byte(s)
|
||||||
RADIOLIB_VERBOSE_PRINT("CMD\t");
|
|
||||||
for(uint8_t n = 0; n < cmdLen; n++) {
|
for(uint8_t n = 0; n < cmdLen; n++) {
|
||||||
spi->transfer(cmd[n]);
|
spi->transfer(cmd[n]);
|
||||||
RADIOLIB_VERBOSE_PRINT(cmd[n], HEX);
|
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
|
||||||
}
|
}
|
||||||
RADIOLIB_VERBOSE_PRINTLN();
|
|
||||||
|
|
||||||
// variable to save error during SPI transfer
|
// variable to save error during SPI transfer
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
|
|
||||||
// send/receive all bytes
|
// send/receive all bytes
|
||||||
RADIOLIB_VERBOSE_PRINT("DAT");
|
|
||||||
if(write) {
|
if(write) {
|
||||||
RADIOLIB_VERBOSE_PRINT("W\t");
|
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
// send byte
|
// send byte
|
||||||
uint8_t in = spi->transfer(dataOut[n]);
|
uint8_t in = spi->transfer(dataOut[n]);
|
||||||
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
#ifdef RADIOLIB_VERBOSE
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
debugBuff[n] = in;
|
||||||
RADIOLIB_VERBOSE_PRINT(in, HEX);
|
#endif
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
|
||||||
|
|
||||||
// check status - SX126X_STATUS_CMD_TIMEOUT is disabled due to regular timeouts
|
// check status
|
||||||
if(//((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
||||||
((in & 0b00001110) == SX126X_STATUS_CMD_INVALID) ||
|
((in & 0b00001110) == SX126X_STATUS_CMD_INVALID) ||
|
||||||
((in & 0b00001110) == SX126X_STATUS_CMD_FAILED)) {
|
((in & 0b00001110) == SX126X_STATUS_CMD_FAILED)) {
|
||||||
status = in & 0b00001110;
|
status = in & 0b00001110;
|
||||||
|
break;
|
||||||
} else if(in == 0x00 || in == 0xFF) {
|
} else if(in == 0x00 || in == 0xFF) {
|
||||||
status = SX126X_STATUS_SPI_FAILED;
|
status = SX126X_STATUS_SPI_FAILED;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RADIOLIB_VERBOSE_PRINTLN();
|
|
||||||
} else {
|
} else {
|
||||||
RADIOLIB_VERBOSE_PRINT("R\t");
|
|
||||||
// skip the first byte for read-type commands (status-only)
|
// skip the first byte for read-type commands (status-only)
|
||||||
uint8_t in = spi->transfer(SX126X_CMD_NOP);
|
uint8_t in = spi->transfer(SX126X_CMD_NOP);
|
||||||
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
#ifdef RADIOLIB_VERBOSE
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
debugBuff[0] = in;
|
||||||
RADIOLIB_VERBOSE_PRINT(in, HEX);
|
#endif
|
||||||
RADIOLIB_VERBOSE_PRINT('\t')
|
|
||||||
|
|
||||||
// check status
|
// check status
|
||||||
if(//((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
||||||
((in & 0b00001110) == SX126X_STATUS_CMD_INVALID) ||
|
((in & 0b00001110) == SX126X_STATUS_CMD_INVALID) ||
|
||||||
((in & 0b00001110) == SX126X_STATUS_CMD_FAILED)) {
|
((in & 0b00001110) == SX126X_STATUS_CMD_FAILED)) {
|
||||||
status = in & 0b00001110;
|
status = in & 0b00001110;
|
||||||
} else if(in == 0x00 || in == 0xFF) {
|
} else if(in == 0x00 || in == 0xFF) {
|
||||||
status = SX126X_STATUS_SPI_FAILED;
|
status = SX126X_STATUS_SPI_FAILED;
|
||||||
|
} else {
|
||||||
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
|
dataIn[n] = spi->transfer(SX126X_CMD_NOP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
|
||||||
dataIn[n] = spi->transfer(SX126X_CMD_NOP);
|
|
||||||
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
|
||||||
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
|
||||||
}
|
|
||||||
RADIOLIB_VERBOSE_PRINTLN();
|
|
||||||
}
|
}
|
||||||
RADIOLIB_VERBOSE_PRINTLN();
|
|
||||||
|
|
||||||
// stop transfer
|
// stop transfer
|
||||||
spi->endTransaction();
|
spi->endTransaction();
|
||||||
|
@ -1364,11 +1357,52 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
start = millis();
|
start = millis();
|
||||||
while(digitalRead(_mod->getRx())) {
|
while(digitalRead(_mod->getRx())) {
|
||||||
if(millis() - start >= timeout) {
|
if(millis() - start >= timeout) {
|
||||||
return(ERR_SPI_CMD_TIMEOUT);
|
status = SX126X_STATUS_CMD_TIMEOUT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print debug output
|
||||||
|
#ifdef RADIOLIB_VERBOSE
|
||||||
|
// print command byte(s)
|
||||||
|
RADIOLIB_VERBOSE_PRINT("CMD\t");
|
||||||
|
for(uint8_t n = 0; n < cmdLen; n++) {
|
||||||
|
RADIOLIB_VERBOSE_PRINT(cmd[n], HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
}
|
||||||
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
|
||||||
|
// print data bytes
|
||||||
|
RADIOLIB_VERBOSE_PRINT("DAT");
|
||||||
|
if(write) {
|
||||||
|
RADIOLIB_VERBOSE_PRINT("W\t");
|
||||||
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
RADIOLIB_VERBOSE_PRINT(debugBuff[n], HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
}
|
||||||
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
} else {
|
||||||
|
RADIOLIB_VERBOSE_PRINT("R\t");
|
||||||
|
// skip the first byte for read-type commands (status-only)
|
||||||
|
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
RADIOLIB_VERBOSE_PRINT(debugBuff[0], HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t')
|
||||||
|
|
||||||
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
|
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
||||||
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
}
|
||||||
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
}
|
||||||
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
#endif
|
||||||
|
|
||||||
// parse status
|
// parse status
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case SX126X_STATUS_CMD_TIMEOUT:
|
case SX126X_STATUS_CMD_TIMEOUT:
|
||||||
|
|
Loading…
Add table
Reference in a new issue