diff --git a/src/Module.cpp b/src/Module.cpp index 7b3c59ae..1f83b7fb 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -61,8 +61,16 @@ int16_t Module::SPIsetRegValue(uint32_t reg, uint8_t value, uint8_t msb, uint8_t return(RADIOLIB_ERR_INVALID_BIT_RANGE); } + // read the current value uint8_t currentValue = SPIreadRegister(reg); uint8_t mask = ~((0b11111111 << (msb + 1)) | (0b11111111 >> (8 - lsb))); + + // check if we actually need to update the register + if((currentValue & mask) == (value & mask)) { + return(RADIOLIB_ERR_NONE); + } + + // update the register uint8_t newValue = (currentValue & ~mask) | (value & mask); SPIwriteRegister(reg, newValue);