From 5f9b2392128cd772ce87fc1ad223c0d6e6a12ee6 Mon Sep 17 00:00:00 2001 From: Ryan Pipkin Date: Tue, 11 Nov 2014 22:05:36 -0600 Subject: [PATCH] Added more registers and avoiding ram for strings. --- RFM69.cpp | 245 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 213 insertions(+), 32 deletions(-) diff --git a/RFM69.cpp b/RFM69.cpp index 9d25c1b..cb4e509 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -430,12 +430,36 @@ void RFM69::setCS(byte newSPISlaveSelect) { //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() { byte regVal; + +#if REGISTER_DETAIL int capVal; - Serial.print ( "Address - HEX - BIN\n" ); + //... State Variables for intelligent decoding + byte modeFSK = 0; + int bitRate = 0; + int freqDev = 0; + long freqCenter = 0; +#endif + + SerialPrint ( "Address - HEX - BIN\n" ); for (byte regAddr = 1; regAddr <= 0x4F; regAddr++) { select(); @@ -449,82 +473,239 @@ void RFM69::readAllRegs() Serial.print(" - "); Serial.println(regVal,BIN); -#if 1 // TODO - make the detailed debug a configurable build option +#if REGISTER_DETAIL switch ( regAddr ) { - case 0x1 :{ - Serial.print ( "\nControls the automatic Sequencer ( see section 4.2 )\nSequencerOff : " ); + case 0x1 : { + SerialPrint ( "Controls the automatic Sequencer ( see section 4.2 )\nSequencerOff : " ); if ( 0x80 & regVal ) { - Serial.println ( "1 -> Mode is forced by the user" ); + SerialPrint ( "1 -> Mode is forced by the user\n" ); } else { - Serial.println ( "0 -> Operating mode as selected with Mode bits in RegOpMode is automatically reached with the Sequencer" ); + SerialPrint ( "0 -> Operating mode as selected with Mode bits in RegOpMode is automatically reached with the Sequencer\n" ); } - Serial.print( "\nEnables Listen mode, should be enabled whilst in Standby mode:\nListenOn : " ); + SerialPrint( "\nEnables Listen mode, should be enabled whilst in Standby mode:\nListenOn : " ); if ( 0x40 & regVal ) { - Serial.println ( "1 -> On" ); + SerialPrint ( "1 -> On\n" ); } else { - Serial.println ( "0 -> Off ( see section 4.3)" ); + SerialPrint ( "0 -> Off ( see section 4.3)\n" ); } - Serial.print( "\nAborts Listen mode when set together with ListenOn=0 See section 4.3.4 for details (Always reads 0.)\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 ) { - Serial.println ( "ERROR - ListenAbort should NEVER return 1" ); + SerialPrint ( "ERROR - ListenAbort should NEVER return 1 this is a write only register\n" ); } - Serial.print("\nTransceiver's operating modes:\nMode : "); + SerialPrint("\nTransceiver's operating modes:\nMode : "); capVal = (regVal >> 2) & 0x7; if ( capVal == 0b000 ) { - Serial.println ( "000 -> Sleep mode (SLEEP)" ); + SerialPrint ( "000 -> Sleep mode (SLEEP)\n" ); } else if ( capVal = 0b001 ) { - Serial.println ( "001 -> Standby mode (STDBY)" ); + SerialPrint ( "001 -> Standby mode (STDBY)\n" ); } else if ( capVal = 0b010 ) { - Serial.println ( "010 -> Frequency Synthesizer mode (FS)" ); + SerialPrint ( "010 -> Frequency Synthesizer mode (FS)\n" ); } else if ( capVal = 0b011 ) { - Serial.println ( "011 -> Transmitter mode (TX)" ); + SerialPrint ( "011 -> Transmitter mode (TX)\n" ); } else if ( capVal = 0b100 ) { - Serial.println ( "100 -> Receiver Mode (RX)" ); + SerialPrint ( "100 -> Receiver Mode (RX)\n" ); } else { Serial.print( capVal, BIN ); - Serial.println ( " -> RESERVED" ); + SerialPrint ( " -> RESERVED\n" ); } - Serial.println ( "" ); + SerialPrint ( "\n" ); break; } case 0x2 : { - Serial.print("\nData Processing mode:\nDataMode : "); + SerialPrint("Data Processing mode:\nDataMode : "); capVal = (regVal >> 5) & 0x3; if ( capVal == 0b00 ) { - Serial.println ( "00 -> Packet mode" ); + SerialPrint ( "00 -> Packet mode\n" ); } else if ( capVal == 0b01 ) { - Serial.println ( "01 -> reserved" ); + SerialPrint ( "01 -> reserved\n" ); } else if ( capVal == 0b10 ) { - Serial.println ( "10 -> Continuous mode with bit synchronizer" ); + SerialPrint ( "10 -> Continuous mode with bit synchronizer\n" ); } else if ( capVal == 0b11 ) { - Serial.println ( "11 -> Continuous mode without bit synchronizer" ); + SerialPrint ( "11 -> Continuous mode without bit synchronizer\n" ); } - Serial.print("\nModulation scheme:\nModulation Type : "); + SerialPrint("\nModulation scheme:\nModulation Type : "); capVal = (regVal >> 3) & 0x3; if ( capVal == 0b00 ) { - Serial.println ( "00 -> FSK" ); + SerialPrint ( "00 -> FSK\n" ); + modeFSK = 1; } else if ( capVal == 0b01 ) { - Serial.println ( "01 -> OOK" ); + SerialPrint ( "01 -> OOK\n" ); } else if ( capVal == 0b10 ) { - Serial.println ( "10 -> reserved" ); + SerialPrint ( "10 -> reserved\n" ); } else if ( capVal == 0b11 ) { - Serial.println ( "11 -> reserved" ); + 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