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"
pull/46/head
mmrein 2019-09-20 11:40:50 +02:00
rodzic ad8c234343
commit 4388cfa06f
2 zmienionych plików z 15 dodań i 4 usunięć

Wyświetl plik

@ -877,20 +877,32 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
if(enabled != true) { if(enabled != true) {
// disable whitening // disable whitening
_whitening = SX126X_GFSK_WHITENING_OFF; _whitening = SX126X_GFSK_WHITENING_OFF;
state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening); state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening);
if(state != ERR_NONE) { if(state != ERR_NONE) {
return(state); return(state);
} }
} else { } 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 // enable whitening
_whitening = SX126X_GFSK_WHITENING_ON; _whitening = SX126X_GFSK_WHITENING_ON;
// write initial whitening value // write initial whitening value
uint8_t data[2] = {(uint8_t)((initial >> 8) & 0xFF), (uint8_t)(initial & 0xFF)}; // 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"
state = writeRegister(SX126X_REG_WHITENING_INITIAL_MSB, data, 2); 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) { if(state != ERR_NONE) {
return(state); 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); state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening);
if(state != ERR_NONE) { if(state != ERR_NONE) {
return(state); return(state);

Wyświetl plik

@ -661,7 +661,6 @@ class SX126x: public PhysicalLayer {
\param enabled True = Whitening enabled \param enabled True = Whitening enabled
\param initial Initial value used for the whitening LFSR in FSK mode. \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 \returns \ref status_codes
*/ */