SX126x whitening: solved 7 MSBs

Proper handling of the datasheet note for Whitening MSB register: "The user should not change the value of the 7 MSB's of this register"
This commit is contained in:
mmrein 2019-09-20 11:40:50 +02:00
parent ad8c234343
commit 4388cfa06f
2 changed files with 15 additions and 4 deletions

View file

@ -877,20 +877,32 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
if(enabled != true) {
// disable whitening
_whitening = SX126X_GFSK_WHITENING_OFF;
state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening);
if(state != ERR_NONE) {
return(state);
}
} else {
// TODO: possibly take care of this note (pg. 65 of datasheet v1.2): "The user should not change the value of the 7 MSB's of this register."
// enable whitening
_whitening = SX126X_GFSK_WHITENING_ON;
// write initial whitening value
uint8_t data[2] = {(uint8_t)((initial >> 8) & 0xFF), (uint8_t)(initial & 0xFF)};
state = writeRegister(SX126X_REG_WHITENING_INITIAL_MSB, data, 2);
// as per note on pg. 65 of datasheet v1.2: "The user should not change the value of the 7 MSB's of this register"
uint8_t data[2];
// first read the actual value and mask 7 MSB which we can not change
// if different value is written in 7 MSB, the Rx won't even work (tested on HW)
state = readRegister(SX126X_REG_WHITENING_INITIAL_MSB, data, 1);
if(state != ERR_NONE) {
return(state);
}
data[0] = (data[0] & 0xFE) | (uint8_t)((initial >> 8) & 0x01);
data[1] = (uint8_t)(initial & 0xFF);
state = writeRegister(SX126X_REG_WHITENING_INITIAL_MSB, data, 2);
if(state != ERR_NONE) {
return(state);
}
state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening);
if(state != ERR_NONE) {
return(state);

View file

@ -661,7 +661,6 @@ class SX126x: public PhysicalLayer {
\param enabled True = Whitening enabled
\param initial Initial value used for the whitening LFSR in FSK mode.
The user should not change the value of the 7 MSB's of this register (pg. 65 of datasheet v1.2)
\returns \ref status_codes
*/