diff --git a/RFM69.cpp b/RFM69.cpp index a931e8f..bcc4926 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -480,11 +480,38 @@ void RFM69::setCS(uint8_t newSPISlaveSelect) { pinMode(_slaveSelectPin, OUTPUT); } -// Serial.print all the RFM69 register values +//for debugging + +#define REGISTER_DETAIL 1 + +#if REGISTER_DETAIL +// SERIAL PRINT +// replace Serial.print("string") with SerialPrint("string") +#define SerialPrint(x) SerialPrint_P(PSTR(x)) +void SerialWrite ( uint8_t c ) { + Serial.write ( c ); +} + +void SerialPrint_P(PGM_P str, void (*f)(uint8_t) = SerialWrite ) { + for (uint8_t c; (c = pgm_read_byte(str)); str++) (*f)(c); +} +#endif + void RFM69::readAllRegs() { uint8_t regVal; +#if REGISTER_DETAIL + int capVal; + + //... State Variables for intelligent decoding + uint8_t modeFSK = 0; + int bitRate = 0; + int freqDev = 0; + long freqCenter = 0; +#endif + + SerialPrint ( "Address - HEX - BIN\n" ); for (uint8_t regAddr = 1; regAddr <= 0x4F; regAddr++) { select(); @@ -497,6 +524,242 @@ void RFM69::readAllRegs() Serial.print(regVal,HEX); Serial.print(" - "); Serial.println(regVal,BIN); + +#if REGISTER_DETAIL + switch ( regAddr ) + { + case 0x1 : { + SerialPrint ( "Controls the automatic Sequencer ( see section 4.2 )\nSequencerOff : " ); + if ( 0x80 & regVal ) { + SerialPrint ( "1 -> Mode is forced by the user\n" ); + } else { + SerialPrint ( "0 -> Operating mode as selected with Mode bits in RegOpMode is automatically reached with the Sequencer\n" ); + } + + SerialPrint( "\nEnables Listen mode, should be enabled whilst in Standby mode:\nListenOn : " ); + if ( 0x40 & regVal ) { + SerialPrint ( "1 -> On\n" ); + } else { + SerialPrint ( "0 -> Off ( see section 4.3)\n" ); + } + + SerialPrint( "\nAborts Listen mode when set together with ListenOn=0 See section 4.3.4 for details (Always reads 0.)\n" ); + if ( 0x20 & regVal ) { + SerialPrint ( "ERROR - ListenAbort should NEVER return 1 this is a write only register\n" ); + } + + SerialPrint("\nTransceiver's operating modes:\nMode : "); + capVal = (regVal >> 2) & 0x7; + if ( capVal == 0b000 ) { + SerialPrint ( "000 -> Sleep mode (SLEEP)\n" ); + } else if ( capVal = 0b001 ) { + SerialPrint ( "001 -> Standby mode (STDBY)\n" ); + } else if ( capVal = 0b010 ) { + SerialPrint ( "010 -> Frequency Synthesizer mode (FS)\n" ); + } else if ( capVal = 0b011 ) { + SerialPrint ( "011 -> Transmitter mode (TX)\n" ); + } else if ( capVal = 0b100 ) { + SerialPrint ( "100 -> Receiver Mode (RX)\n" ); + } else { + Serial.print( capVal, BIN ); + SerialPrint ( " -> RESERVED\n" ); + } + SerialPrint ( "\n" ); + break; + } + + case 0x2 : { + + SerialPrint("Data Processing mode:\nDataMode : "); + capVal = (regVal >> 5) & 0x3; + if ( capVal == 0b00 ) { + SerialPrint ( "00 -> Packet mode\n" ); + } else if ( capVal == 0b01 ) { + SerialPrint ( "01 -> reserved\n" ); + } else if ( capVal == 0b10 ) { + SerialPrint ( "10 -> Continuous mode with bit synchronizer\n" ); + } else if ( capVal == 0b11 ) { + SerialPrint ( "11 -> Continuous mode without bit synchronizer\n" ); + } + + SerialPrint("\nModulation scheme:\nModulation Type : "); + capVal = (regVal >> 3) & 0x3; + if ( capVal == 0b00 ) { + SerialPrint ( "00 -> FSK\n" ); + modeFSK = 1; + } else if ( capVal == 0b01 ) { + SerialPrint ( "01 -> OOK\n" ); + } else if ( capVal == 0b10 ) { + SerialPrint ( "10 -> reserved\n" ); + } else if ( capVal == 0b11 ) { + SerialPrint ( "11 -> reserved\n" ); + } + + SerialPrint("\nData shaping: "); + if ( modeFSK ) { + SerialPrint( "in FSK:\n" ); + } else { + SerialPrint( "in OOK:\n" ); + } + SerialPrint ("ModulationShaping : "); + capVal = regVal & 0x3; + if ( modeFSK ) { + if ( capVal == 0b00 ) { + SerialPrint ( "00 -> no shaping\n" ); + } else if ( capVal == 0b01 ) { + SerialPrint ( "01 -> Gaussian filter, BT = 1.0\n" ); + } else if ( capVal == 0b10 ) { + SerialPrint ( "10 -> Gaussian filter, BT = 0.5\n" ); + } else if ( capVal == 0b11 ) { + SerialPrint ( "11 -> Gaussian filter, BT = 0.3\n" ); + } + } else { + if ( capVal == 0b00 ) { + SerialPrint ( "00 -> no shaping\n" ); + } else if ( capVal == 0b01 ) { + SerialPrint ( "01 -> filtering with f(cutoff) = BR\n" ); + } else if ( capVal == 0b10 ) { + SerialPrint ( "10 -> filtering with f(cutoff) = 2*BR\n" ); + } else if ( capVal == 0b11 ) { + SerialPrint ( "ERROR - 11 is reserved\n" ); + } + } + + SerialPrint ( "\n" ); + break; + } + + case 0x3 : { + bitRate = (regVal << 8); + break; + } + + case 0x4 : { + bitRate |= regVal; + SerialPrint ( "Bit Rate (Chip Rate when Manchester encoding is enabled)\nBitRate : "); + unsigned long val = 32UL * 1000UL * 1000UL / bitRate; + Serial.println( val ); + SerialPrint( "\n" ); + break; + } + + case 0x5 : { + freqDev = ( (regVal & 0x3f) << 8 ); + break; + } + + case 0x6 : { + freqDev |= regVal; + SerialPrint( "Frequency deviation\nFdev : " ); + unsigned long val = 61UL * freqDev; + Serial.println( val ); + SerialPrint ( "\n" ); + break; + } + + case 0x7 : { + unsigned long tempVal = regVal; + freqCenter = ( tempVal << 16 ); + break; + } + + case 0x8 : { + unsigned long tempVal = regVal; + freqCenter = freqCenter | ( tempVal << 8 ); + break; + } + + case 0x9 : { + freqCenter = freqCenter | regVal; + SerialPrint ( "RF Carrier frequency\nFRF : " ); + unsigned long val = 61UL * freqCenter; + Serial.println( val ); + SerialPrint( "\n" ); + break; + } + + case 0xa : { + SerialPrint ( "RC calibration control & status\nRcCalDone : " ); + if ( 0x40 & regVal ) { + SerialPrint ( "1 -> RC calibration is over\n" ); + } else { + SerialPrint ( "0 -> RC calibration is in progress\n" ); + } + + SerialPrint ( "\n" ); + break; + } + + case 0xb : { + SerialPrint ( "Improved AFC routine for signals with modulation index lower than 2. Refer to section 3.4.16 for details\nAfcLowBetaOn : " ); + if ( 0x20 & regVal ) { + SerialPrint ( "1 -> Improved AFC routine\n" ); + } else { + SerialPrint ( "0 -> Standard AFC routine\n" ); + } + SerialPrint ( "\n" ); + break; + } + + case 0xc : { + SerialPrint ( "Reserved\n\n" ); + break; + } + + case 0xd : { + byte val; + SerialPrint ( "Resolution of Listen mode Idle time (calibrated RC osc):\nListenResolIdle : " ); + val = regVal >> 6; + if ( val == 0b00 ) { + SerialPrint ( "00 -> reserved\n" ); + } else if ( val == 0b01 ) { + SerialPrint ( "01 -> 64 us\n" ); + } else if ( val == 0b10 ) { + SerialPrint ( "10 -> 4.1 ms\n" ); + } else if ( val == 0b11 ) { + SerialPrint ( "11 -> 262 ms\n" ); + } + + SerialPrint ( "\nResolution of Listen mode Rx time (calibrated RC osc):\nListenResolRx : " ); + val = (regVal >> 4) & 0x3; + if ( val == 0b00 ) { + SerialPrint ( "00 -> reserved\n" ); + } else if ( val == 0b01 ) { + SerialPrint ( "01 -> 64 us\n" ); + } else if ( val == 0b10 ) { + SerialPrint ( "10 -> 4.1 ms\n" ); + } else if ( val == 0b11 ) { + SerialPrint ( "11 -> 262 ms\n" ); + } + + SerialPrint ( "\nCriteria for packet acceptance in Listen mode:\nListenCriteria : " ); + if ( 0x8 & regVal ) { + SerialPrint ( "1 -> signal strength is above RssiThreshold and SyncAddress matched\n" ); + } else { + SerialPrint ( "0 -> signal strength is above RssiThreshold\n" ); + } + + SerialPrint ( "\nAction taken after acceptance of a packet in Listen mode:\nListenEnd : " ); + val = (regVal >> 1 ) & 0x3; + if ( val == 0b00 ) { + SerialPrint ( "00 -> chip stays in Rx mode. Listen mode stops and must be disabled (see section 4.3)\n" ); + } else if ( val == 0b01 ) { + SerialPrint ( "01 -> chip stays in Rx mode until PayloadReady or Timeout interrupt occurs. It then goes to the mode defined by Mode. Listen mode stops and must be disabled (see section 4.3)\n" ); + } else if ( val == 0b10 ) { + SerialPrint ( "10 -> chip stays in Rx mode until PayloadReady or Timeout occurs. Listen mode then resumes in Idle state. FIFO content is lost at next Rx wakeup.\n" ); + } else if ( val == 0b11 ) { + SerialPrint ( "11 -> Reserved\n" ); + } + + + SerialPrint ( "\n" ); + break; + } + + default : { + } + } +#endif } unselect(); }