Added option to disable "paranoid" SPI mode (enabled by default)
This commit is contained in:
parent
4461e9a98e
commit
9a9af85fdc
2 changed files with 41 additions and 30 deletions
|
@ -390,6 +390,13 @@
|
|||
|
||||
//#define RADIOLIB_STATIC_ONLY
|
||||
|
||||
/*
|
||||
* Uncomment to enable "paranoid" SPI mode
|
||||
* Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
|
||||
* This improves reliablility, but slightly slows down communication.
|
||||
*/
|
||||
#define RADIOLIB_SPI_PARANOID
|
||||
|
||||
// set the size of static arrays to use
|
||||
#if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
|
||||
#define RADIOLIB_STATIC_ARRAY_SIZE 256
|
||||
|
|
|
@ -216,39 +216,43 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
|||
uint8_t newValue = (currentValue & ~mask) | (value & mask);
|
||||
SPIwriteRegister(reg, newValue);
|
||||
|
||||
// check register value each millisecond until check interval is reached
|
||||
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
|
||||
uint32_t start = Module::micros();
|
||||
uint8_t readValue = 0x00;
|
||||
while(Module::micros() - start < (checkInterval * 1000)) {
|
||||
readValue = SPIreadRegister(reg);
|
||||
if(readValue == newValue) {
|
||||
// check passed, we can stop the loop
|
||||
return(ERR_NONE);
|
||||
#if defined(RADIOLIB_SPI_PARANOID)
|
||||
// check register value each millisecond until check interval is reached
|
||||
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
|
||||
uint32_t start = Module::micros();
|
||||
uint8_t readValue = 0x00;
|
||||
while(Module::micros() - start < (checkInterval * 1000)) {
|
||||
readValue = SPIreadRegister(reg);
|
||||
if(readValue == newValue) {
|
||||
// check passed, we can stop the loop
|
||||
return(ERR_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check failed, print debug info
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
RADIOLIB_DEBUG_PRINT(F("address:\t0x"));
|
||||
RADIOLIB_DEBUG_PRINTLN(reg, HEX);
|
||||
RADIOLIB_DEBUG_PRINT(F("bits:\t\t"));
|
||||
RADIOLIB_DEBUG_PRINT(msb);
|
||||
RADIOLIB_DEBUG_PRINT(' ');
|
||||
RADIOLIB_DEBUG_PRINTLN(lsb);
|
||||
RADIOLIB_DEBUG_PRINT(F("value:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(value, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("current:\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(currentValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(mask, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("new:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(newValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("read:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(readValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
// check failed, print debug info
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
RADIOLIB_DEBUG_PRINT(F("address:\t0x"));
|
||||
RADIOLIB_DEBUG_PRINTLN(reg, HEX);
|
||||
RADIOLIB_DEBUG_PRINT(F("bits:\t\t"));
|
||||
RADIOLIB_DEBUG_PRINT(msb);
|
||||
RADIOLIB_DEBUG_PRINT(' ');
|
||||
RADIOLIB_DEBUG_PRINTLN(lsb);
|
||||
RADIOLIB_DEBUG_PRINT(F("value:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(value, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("current:\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(currentValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(mask, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("new:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(newValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINT(F("read:\t\t0b"));
|
||||
RADIOLIB_DEBUG_PRINTLN(readValue, BIN);
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
|
||||
return(ERR_SPI_WRITE_FAILED);
|
||||
return(ERR_SPI_WRITE_FAILED);
|
||||
#else
|
||||
return(ERR_NONE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Module::SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes) {
|
||||
|
|
Loading…
Add table
Reference in a new issue