Low Battery Detector
I then test the low battery detector which I already tested OK some months ago. The retesting was smooth. I set the low voltage level at 2.8V, ran the program, then by hand lower the power supply voltage from 3.2V to 2.9V at which point the RFM12B nIRQ activates to low voltage.
So the 3 basic tests - external clock, wakeup timer, and low battery detector are all OK.
So far I have been using the power up defaults for the RFM12B configuration.
Next step is to study the configuration setting, which is very tedious.
void RFM12Btest01()
{
RFM12B40 rfm1(SCK_PIN, SDO_PIN, SDI_PIN, CS_PIN, NIRQ_PIN);
// *** test SPI output pins
// rfm1.testArduinoPins(100, 1000); // switching CS, DSO, CLK (Pins 10, 11, 13) HIGH/LOW 1 second 100 times
// *** test changing RFM12B external MCU clock frequency
// repeat 10 times changing ext mcu clock (pin 8) in steps from 1 MHz to 10MHz
// rfm1.testExternalMCUclock();
// *** test wake up timer
// repeatedly generate one 2mS interrupt every 10mS (RFM12B nIRQ Pin 4 > ULN2003A 5>6>7>8 > Arduino Int0, Pin 2)
// rfm1.testWakeUpTimer0210();
// *** test low battery detector 2.2V RFM12B nIRQ Pin 4)
rfm1.testLowBatteryDetectorV28(); }
{
RFM12B40 rfm1(SCK_PIN, SDO_PIN, SDI_PIN, CS_PIN, NIRQ_PIN);
// *** test SPI output pins
// rfm1.testArduinoPins(100, 1000); // switching CS, DSO, CLK (Pins 10, 11, 13) HIGH/LOW 1 second 100 times
// *** test changing RFM12B external MCU clock frequency
// repeat 10 times changing ext mcu clock (pin 8) in steps from 1 MHz to 10MHz
// rfm1.testExternalMCUclock();
// *** test wake up timer
// repeatedly generate one 2mS interrupt every 10mS (RFM12B nIRQ Pin 4 > ULN2003A 5>6>7>8 > Arduino Int0, Pin 2)
// rfm1.testWakeUpTimer0210();
// *** test low battery detector 2.2V RFM12B nIRQ Pin 4)
rfm1.testLowBatteryDetectorV28(); }
// *********************************************************************
// System - SROS (Shamshuipo Robot Operating System)
// Description - Arduino based software for toy robot DIY hobbists
// Author - TL Fong [http://hk.myblog.yahoo.com/tlfong01@yahoo.cn]
// Date - 2008 October
// Hardware - Arduino Decimila 2008
// Software - Arduino IDE 0017
// Copyright - CC3.0 Free software for DIY hobbists, learning and fun
// *********************************************************************
// System - SROS (Shamshuipo Robot Operating System)
// Description - Arduino based software for toy robot DIY hobbists
// Author - TL Fong [http://hk.myblog.yahoo.com/tlfong01@yahoo.cn]
// Date - 2008 October
// Hardware - Arduino Decimila 2008
// Software - Arduino IDE 0017
// Copyright - CC3.0 Free software for DIY hobbists, learning and fun
// *********************************************************************
// *********************************************************************
// File - test_rfm12b_v03_2009dec0401.pdr
// Function - Test RFM12B changing external mpu clock frequency
// Version - 0.5
// Last update - 2009dec04hkt2138
// *********************************************************************
// File - test_rfm12b_v03_2009dec0401.pdr
// Function - Test RFM12B changing external mpu clock frequency
// Version - 0.5
// Last update - 2009dec04hkt2138
// *********************************************************************
// #include
#include // Arduino pins
#include // Devices (LED, LCD, buzzer etc)
#include // Device and signal names
#include // Timers in microseconds, milliseconds, half seconds, and seconds
#include // Arduino Pin 13 LED
#include // 4 bit data bus, 4 bit address bus, 4 bit control bus
#include // 4-line to 16-line address decoder (SN74HC137)
#include // Octal data latch (SN74HC573)
#include // Electronmagenti buzzer driven by hc 573
#include // 16x2 and 20x4 LCD
#include // 4 column x 3 row key pad
#include // Basic Input Out System
#include // Seven segment LED's decimal points driven by hc573
#include // Seven segment LED
#include
#include // Arduino pins
#include // Devices (LED, LCD, buzzer etc)
#include // Device and signal names
#include // Timers in microseconds, milliseconds, half seconds, and seconds
#include // Arduino Pin 13 LED
#include // 4 bit data bus, 4 bit address bus, 4 bit control bus
#include // 4-line to 16-line address decoder (SN74HC137)
#include // Octal data latch (SN74HC573)
#include // Electronmagenti buzzer driven by hc 573
#include // 16x2 and 20x4 LCD
#include // 4 column x 3 row key pad
#include // Basic Input Out System
#include // Seven segment LED's decimal points driven by hc573
#include // Seven segment LED
#include
void RFM12Btest01()
{
RFM12B40 rfm1(SCK_PIN, SDO_PIN, SDI_PIN, CS_PIN, NIRQ_PIN);
// *** test SPI output pins
// rfm1.testArduinoPins(100, 1000); // switching CS, DSO, CLK (Pins 10, 11, 13) HIGH/LOW 1 second 100 times
// *** test changing RFM12B external MCU clock frequency
// repeat 10 times changing ext mcu clock (pin 8) in steps from 1 MHz to 10MHz
// rfm1.testExternalMCUclock();
// *** test wake up timer
// repeatedly generate one 2mS interrupt every 10mS (RFM12B nIRQ Pin 4 > ULN2003A 5>6>7>8 > Arduino Int0, Pin 2)
// rfm1.testWakeUpTimer0210();
// *** test low battery detector 2.2V RFM12B nIRQ Pin 4)
rfm1.testLowBatteryDetectorV28(); }
{
RFM12B40 rfm1(SCK_PIN, SDO_PIN, SDI_PIN, CS_PIN, NIRQ_PIN);
// *** test SPI output pins
// rfm1.testArduinoPins(100, 1000); // switching CS, DSO, CLK (Pins 10, 11, 13) HIGH/LOW 1 second 100 times
// *** test changing RFM12B external MCU clock frequency
// repeat 10 times changing ext mcu clock (pin 8) in steps from 1 MHz to 10MHz
// rfm1.testExternalMCUclock();
// *** test wake up timer
// repeatedly generate one 2mS interrupt every 10mS (RFM12B nIRQ Pin 4 > ULN2003A 5>6>7>8 > Arduino Int0, Pin 2)
// rfm1.testWakeUpTimer0210();
// *** test low battery detector 2.2V RFM12B nIRQ Pin 4)
rfm1.testLowBatteryDetectorV28(); }
void RFM12Btest01menu()
{
BIOS40 b1(DATA_PINS, ADDRESS_PINS, CONTROL_PINS, DECODER_PINS); // create BIOS40 object
b1.sayHello(LCD_01, "2009dec04", LCD_02, "Hello");
b1.initBus(); // setting up Arduino pins
b1.blink(2); // blink Arduino system LED (Pin 13)
b1.beep(4); // beep 4
b1.waitSecond(2);
{
BIOS40 b1(DATA_PINS, ADDRESS_PINS, CONTROL_PINS, DECODER_PINS); // create BIOS40 object
b1.sayHello(LCD_01, "2009dec04", LCD_02, "Hello");
b1.initBus(); // setting up Arduino pins
b1.blink(2); // blink Arduino system LED (Pin 13)
b1.beep(4); // beep 4
b1.waitSecond(2);
b1.blankLCD(LCD_01); // initialize and blank two
b1.blankLCD(LCD_02); // 16x2, and 20x4 LCD modules
b1.waitSecond(2);
b1.displayLCDdigit01(LCD_01, 2, 2, 3); // display 1 decimal digit in LCD #1
b1.displayLCDdigit01(LCD_02, 2, 2, 4); // display 1 decimal digit in LCD #2
b1.waitSecond(2);
b1.blankLCD(LCD_02); // 16x2, and 20x4 LCD modules
b1.waitSecond(2);
b1.displayLCDdigit01(LCD_01, 2, 2, 3); // display 1 decimal digit in LCD #1
b1.displayLCDdigit01(LCD_02, 2, 2, 4); // display 1 decimal digit in LCD #2
b1.waitSecond(2);
b1.displayLCDstring(LCD_01, "LCD01 2009dec0401"); // display string in LCD #1
b1.displayLCDstring(LCD_02, "Test RFM12B 01"); // display string in LCD #2
b1.waitSecond(2);
b1.displayLCDstring(LCD_02, "Test RFM12B 01"); // display string in LCD #2
b1.waitSecond(2);
b1.menu(); // menu system
b1.sayGoodBye(LCD_01, "2009dec04", LCD_02, "Good Bye");
b1.waitForever(); // loop forever
// b1.scanAddressDecoder(); // scan 16 decoder LED indictators
// b1.blink4BitDataLatch2(); // blink data latch 2's 4 bits (Buzzer and 3 LEDs)
// b1.blank4SevenSegmentLED(LED_11); // initialize and blank three
// b1.blank4SevenSegmentLED(LED_21); // 4-digit and 3-digit seven-segment LED modules
// b1.blank2SevenSegmentLED(LED_31);
// b1.display1DecimalDigit(LED_11, 1); // display 1 decimal digit in LED11
// b1.display1DecimalDigit(LED_21, 2); // display 1 decimal digit in LED21
// b1.display1DecimalDigit(LED_31, 3); // display 1 decimal digit in LED31
// b1.display10SevenSegmentDigit(); // display 10 digits in 3 LCDs
// b1.blinkDecimalPoint(); // blink 4 decimal points
}
void setup()
{
}
b1.sayGoodBye(LCD_01, "2009dec04", LCD_02, "Good Bye");
b1.waitForever(); // loop forever
// b1.scanAddressDecoder(); // scan 16 decoder LED indictators
// b1.blink4BitDataLatch2(); // blink data latch 2's 4 bits (Buzzer and 3 LEDs)
// b1.blank4SevenSegmentLED(LED_11); // initialize and blank three
// b1.blank4SevenSegmentLED(LED_21); // 4-digit and 3-digit seven-segment LED modules
// b1.blank2SevenSegmentLED(LED_31);
// b1.display1DecimalDigit(LED_11, 1); // display 1 decimal digit in LED11
// b1.display1DecimalDigit(LED_21, 2); // display 1 decimal digit in LED21
// b1.display1DecimalDigit(LED_31, 3); // display 1 decimal digit in LED31
// b1.display10SevenSegmentDigit(); // display 10 digits in 3 LCDs
// b1.blinkDecimalPoint(); // blink 4 decimal points
}
void setup()
{
}
void loop()
{
RFM12Btest01();
while (1) { }
}
{
RFM12Btest01();
while (1) { }
}
// *********************************************************************
// End
// *********************************************************************
// End
// *********************************************************************
// RFM12B40.h tlfong 2009dec04hkt1432
#ifndef RFM12B40_h
#define RFM12B40_h
#define RFM12B40_h
#include "WProgram.h"
class RFM12B40
{
public:
RFM12B40(int sckPin, int sdoPin, int sdiPin, int csPin, int nIrqPin);
void configArduinoPins();
void testArduinoPins();
void putWord(unsigned int xWord);
void testArduinoPins(int xCount, int xTime);
void enableExternalMcuClock();
void setupClockFrequency(int frequency);
void testExternalMCUclock();
void clearInterrupt();
void setupWakeUpTimer(int timePeriod);
void testSetupWakeUpTimer2MilliSeconds();
void calibrateWakeUpTimer(int xTimePeriod);
void testWakeUpTimer(int xTime1, int xTime2);
void testWakeUpTimer0210();
void enableLowBatteryDetector();
void disableLowBatteryDetector();
void setupLowBatteryDetector(int xLowVoltageLevel);
void testLowBatteryDetectorV28();
void configRfm12bSoftwareDefault();
void configRfm12bHardwareDefault();
void sendChar(unsigned char data);
void sendFrame();
void enableWakeUpTimer();
void disableWakeUpTimer();
void disableRxFifoMode();
void enableRxFifoMode();
void enableBaseBandClockPower();
void disableBaseBandClockPower();
void enableReceiverPower();
void disableReceiverPower();
void testReceiverClock9600Hz();
void testReceiverClock4800Hz();
void testReceiverClock2400Hz();
void enableNonFifoReceiverMode();
void setupDataRate2400Hz();
void setupDataRate4800Hz();
void setupDataRate9600Hz();
void testDataRateCycle();
void selectTransmitterAndBaseBandClockPower();
void selectReceiverPower();
void transmitByte(byte xByte);
void testTransmitBytesNonStop01();
void testTransmitBytesNonStop01a();
void testTransmitBytesNonStop02(int betweenCharactersDelay);
void testTransmitBytesNonStop04();
void configTxBufferedRxNonFifoMode();
void switchPowerOnEverything();
void changeTransceiverToNonFifoReceiver();
void changeTransceiverToBufferedTransmitter();
void testNonFifoReceiver01();
void testBufferedTransmitter01();
void resetRfm12bInterrupt();
void testTransmitBytesNonStop04a();
void testNonFifoReceiver04a();
void selectTransmitterNoBufferReceiverNoBufferConfiguration();
void selectTransmitterOperation();
void selectReceiverOperation();
void testTransmitBytesNonStop05();
void selectTxbRxfifoConfig(); // test tx buffer rx fifo 2009aug10hkt1433 tlfong01
void selectTxbOperation();
void selectRxfifoOperation();
void testTxB01();
void testRxFifo01();
void xmitByte01(byte xByte);
void xmitPacket01();
void recvPacket02();
void setupClockFrequency5Mhz();
void setExtMcuClkFreq(int xFreq);
void setNonFifoRxAndDataRate(int xDataRate);
void setWakeUpTimer(int xTimePeriod);
void testWakeUpTimer(int xTime1, int xTime2, int xCount);
void setNonFifoBufferRxRegisterBufferTxMode(); // *** not yet tested ***
void setNonFifoBufferRxNonRegisterBufferTxMode(); // *** to test now ***
void selectOperation(int xOperation);
void setLowBatteryVoltageLevel(int xLowBatteryVoltage);
void testTransmitBytesNonStop06();
private:
int _sckPin;
int _sdoPin;
int _sdiPin;
int _csPin;
int _nIrqPin;
int _commands[17];
};
{
public:
RFM12B40(int sckPin, int sdoPin, int sdiPin, int csPin, int nIrqPin);
void configArduinoPins();
void testArduinoPins();
void putWord(unsigned int xWord);
void testArduinoPins(int xCount, int xTime);
void enableExternalMcuClock();
void setupClockFrequency(int frequency);
void testExternalMCUclock();
void clearInterrupt();
void setupWakeUpTimer(int timePeriod);
void testSetupWakeUpTimer2MilliSeconds();
void calibrateWakeUpTimer(int xTimePeriod);
void testWakeUpTimer(int xTime1, int xTime2);
void testWakeUpTimer0210();
void enableLowBatteryDetector();
void disableLowBatteryDetector();
void setupLowBatteryDetector(int xLowVoltageLevel);
void testLowBatteryDetectorV28();
void configRfm12bSoftwareDefault();
void configRfm12bHardwareDefault();
void sendChar(unsigned char data);
void sendFrame();
void enableWakeUpTimer();
void disableWakeUpTimer();
void disableRxFifoMode();
void enableRxFifoMode();
void enableBaseBandClockPower();
void disableBaseBandClockPower();
void enableReceiverPower();
void disableReceiverPower();
void testReceiverClock9600Hz();
void testReceiverClock4800Hz();
void testReceiverClock2400Hz();
void enableNonFifoReceiverMode();
void setupDataRate2400Hz();
void setupDataRate4800Hz();
void setupDataRate9600Hz();
void testDataRateCycle();
void selectTransmitterAndBaseBandClockPower();
void selectReceiverPower();
void transmitByte(byte xByte);
void testTransmitBytesNonStop01();
void testTransmitBytesNonStop01a();
void testTransmitBytesNonStop02(int betweenCharactersDelay);
void testTransmitBytesNonStop04();
void configTxBufferedRxNonFifoMode();
void switchPowerOnEverything();
void changeTransceiverToNonFifoReceiver();
void changeTransceiverToBufferedTransmitter();
void testNonFifoReceiver01();
void testBufferedTransmitter01();
void resetRfm12bInterrupt();
void testTransmitBytesNonStop04a();
void testNonFifoReceiver04a();
void selectTransmitterNoBufferReceiverNoBufferConfiguration();
void selectTransmitterOperation();
void selectReceiverOperation();
void testTransmitBytesNonStop05();
void selectTxbRxfifoConfig(); // test tx buffer rx fifo 2009aug10hkt1433 tlfong01
void selectTxbOperation();
void selectRxfifoOperation();
void testTxB01();
void testRxFifo01();
void xmitByte01(byte xByte);
void xmitPacket01();
void recvPacket02();
void setupClockFrequency5Mhz();
void setExtMcuClkFreq(int xFreq);
void setNonFifoRxAndDataRate(int xDataRate);
void setWakeUpTimer(int xTimePeriod);
void testWakeUpTimer(int xTime1, int xTime2, int xCount);
void setNonFifoBufferRxRegisterBufferTxMode(); // *** not yet tested ***
void setNonFifoBufferRxNonRegisterBufferTxMode(); // *** to test now ***
void selectOperation(int xOperation);
void setLowBatteryVoltageLevel(int xLowBatteryVoltage);
void testTransmitBytesNonStop06();
private:
int _sckPin;
int _sdoPin;
int _sdiPin;
int _csPin;
int _nIrqPin;
int _commands[17];
};
// *** RFM12B Commands
#define CLEAR_INTERRUPT 0x0000
// *** RFM12B Command Numbering
#define COMMAND_CONFIGURATION_SETTING 0
#define COMMAND_POWER_MANAGEMENT 1
#define COMMAND_FREQUENCY_SETTING 2
#define COMMAND_DATA_RATE 3
#define COMMAND_RECEIVER_CONTROL 4
#define COMMAND_DATA_FILTER 5
#define COMMAND_FIFO_AND_RESET_MODE 6
#define COMMAND_SYNCHRON_PATTERN 7
#define COMMAND_RECEIVER_FIFO_READ 8
#define COMMAND_AFC 9
#define COMMAND_TX_CONFIGURATION_CONTROL 10
#define COMMAND_PLL_SETTING 11
#define COMMAND_TRANSMITTER_REGISTER_WRITE 12
#define COMMAND_WAKE_UP_TIMER 13
#define COMMAND_LOW_DUTY_CYCLE 14
#define COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER 15
#define COMMAND_STATUS_READ 16
#define COMMAND_POWER_MANAGEMENT 1
#define COMMAND_FREQUENCY_SETTING 2
#define COMMAND_DATA_RATE 3
#define COMMAND_RECEIVER_CONTROL 4
#define COMMAND_DATA_FILTER 5
#define COMMAND_FIFO_AND_RESET_MODE 6
#define COMMAND_SYNCHRON_PATTERN 7
#define COMMAND_RECEIVER_FIFO_READ 8
#define COMMAND_AFC 9
#define COMMAND_TX_CONFIGURATION_CONTROL 10
#define COMMAND_PLL_SETTING 11
#define COMMAND_TRANSMITTER_REGISTER_WRITE 12
#define COMMAND_WAKE_UP_TIMER 13
#define COMMAND_LOW_DUTY_CYCLE 14
#define COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER 15
#define COMMAND_STATUS_READ 16
#define COMMAND_EXT_MCU_CLK_FREQ 15
#define COMMAND_DATA_RATE 5
#define COMMAND_LOW_BATTERY_DETECTOR 15
#define COMMAND_DATA_RATE 5
#define COMMAND_LOW_BATTERY_DETECTOR 15
// *** RFM12B External MCU Clock Frequency Setting
// mcu clock frequency 17
#define EXTERNAL_MCU_CLOCK_MASK 0x00E0 // bits 5, 6, 7 0000 0000 1110 0000
#define ENABLE_EXTERNAL_MCU_CLOCK 0x0008
#define DISABLE_CLOCK_OUTPUT 0x0001 // not yet tested
#define ENABLE_EXTERNAL_MCU_CLOCK 0x0008
#define DISABLE_CLOCK_OUTPUT 0x0001 // not yet tested
#define MHZ0100 0x0010
#define MHZ0125 0x0020
#define MHZ0166 0x0040
#define MHZ0200 0x0060
#define MHZ0250 0x0080
#define MHZ0330 0x00A0
#define MHZ0500 0x00C0
#define MHZ1000 0x00E0
#define MHZ0125 0x0020
#define MHZ0166 0x0040
#define MHZ0200 0x0060
#define MHZ0250 0x0080
#define MHZ0330 0x00A0
#define MHZ0500 0x00C0
#define MHZ1000 0x00E0
// d2 d1 d0 MHz 16 bit
// 0 0 0 1.00 0x0010
// 0 0 1 1.25 0x0020
// 0 1 0 1.66 0x0040
// 0 1 1 2.00 0x0060
// 1 0 0 2.50 0x0080
// 1 0 1 3.33 0x00A0
// 1 1 0 5.00 0x00C0
// 1 1 1 10.00 0x00E0
// 0 0 0 1.00 0x0010
// 0 0 1 1.25 0x0020
// 0 1 0 1.66 0x0040
// 0 1 1 2.00 0x0060
// 1 0 0 2.50 0x0080
// 1 0 1 3.33 0x00A0
// 1 1 0 5.00 0x00C0
// 1 1 1 10.00 0x00E0
// *** wake up timer setting
#define ENABLE_WAKE_UP_TIMER 0x0002
#define ENABLE_OSCILLATOR 0x0020
#define ENABLE_OSCILLATOR 0x0020
#define MILLI_SECONDS_0001 0xE001 //
#define MILLI_SECONDS_0002 0xE002 //
#define MILLI_SECONDS_0003 0xE003 //
#define MILLI_SECONDS_0004 0xE004 //
#define MILLI_SECONDS_0008 0xE008 //
#define MILLI_SECONDS_0016 0xE010 //
#define MILLI_SECONDS_0002 0xE001 // 2**1 = 2, 2**0 = 1
#define MILLI_SECONDS_0250 0xE0FA // 1110 0000 1111 1010
#define MILLI_SECONDS_0500 0xE1FA // 1110 0001 1111 1010
#define MILLI_SECONDS_1000 0xE2FA // 1110 0010 1111 1010
#define SECONDS_0001 0xE2FA // 1110 0010 1111 1010 1 seconds
#define SECONDS_0002 0xE4FA // 1110 0100 1111 1010 2 seconds
#define SECONDS_0004 0xE8FA // 1110 1000 1111 1010 4 seconds about 1 minute
#define SECONDS_0008 0xF0FA // 1111 0000 1111 1010 8 seconds
#define SECONDS_0016 0xF1FA // 1111 0001 1111 1010 16 seconds
#define SECONDS_0032 0xF2FA // 1111 0010 1111 1010 32 seconds
#define MINUTES_0001 0xF8EA // 1111 1000 1111 1010 1 minutes
#define MILLI_SECONDS_0002 0xE002 //
#define MILLI_SECONDS_0003 0xE003 //
#define MILLI_SECONDS_0004 0xE004 //
#define MILLI_SECONDS_0008 0xE008 //
#define MILLI_SECONDS_0016 0xE010 //
#define MILLI_SECONDS_0002 0xE001 // 2**1 = 2, 2**0 = 1
#define MILLI_SECONDS_0250 0xE0FA // 1110 0000 1111 1010
#define MILLI_SECONDS_0500 0xE1FA // 1110 0001 1111 1010
#define MILLI_SECONDS_1000 0xE2FA // 1110 0010 1111 1010
#define SECONDS_0001 0xE2FA // 1110 0010 1111 1010 1 seconds
#define SECONDS_0002 0xE4FA // 1110 0100 1111 1010 2 seconds
#define SECONDS_0004 0xE8FA // 1110 1000 1111 1010 4 seconds about 1 minute
#define SECONDS_0008 0xF0FA // 1111 0000 1111 1010 8 seconds
#define SECONDS_0016 0xF1FA // 1111 0001 1111 1010 16 seconds
#define SECONDS_0032 0xF2FA // 1111 0010 1111 1010 32 seconds
#define MINUTES_0001 0xF8EA // 1111 1000 1111 1010 1 minutes
// period = m * (2 ** r) [mS]
// m = bits 0 -7
// r = bits 8 - 12
// m = bits 0 -7
// r = bits 8 - 12
// *** Low battery setting
#define ENABLE_LOW_BATTERY_DETECTOR 0x0004
#define LOW_BATTERY_DETECTOR_MASK 0x000F // bits 0 to 4
#define VOLT_0220 0x0000 // **** **** 000* **** = 2.2 + 0 * 0.1 (0.05V hystersis)
#define VOLT_0240 0x0002 // **** **** 010* **** = 2.2 + 2 * 0.1
#define VOLT_0260 0x0004 // **** **** 100* **** = 2.2 + 4 * 0.1
#define VOLT_0280 0x0006 // **** **** 010* **** = 2.2 + 6 * 0.1
#define VOLT_0300 0x0008 // **** **** 010* **** = 2.2 + 8 * 0.1
#define LOW_BATTERY_DETECTOR_MASK 0x000F // bits 0 to 4
#define VOLT_0220 0x0000 // **** **** 000* **** = 2.2 + 0 * 0.1 (0.05V hystersis)
#define VOLT_0240 0x0002 // **** **** 010* **** = 2.2 + 2 * 0.1
#define VOLT_0260 0x0004 // **** **** 100* **** = 2.2 + 4 * 0.1
#define VOLT_0280 0x0006 // **** **** 010* **** = 2.2 + 6 * 0.1
#define VOLT_0300 0x0008 // **** **** 010* **** = 2.2 + 8 * 0.1
// *** Configuration setting - 2009sep21
#define ENABLE_TX_REGISTER_BUFFER 0x0080 // set Tx
#define ENABLE_RX_FIFO_BUFFER 0x0040 // set Rx
// *** Configuration setting - 2009aug07
#define TX_YBF_RX_NBF_CONFIGURATION 0x8097 // Tx yes buffer, Rx no buffer, 433Mhz, 12pF
#define TX_NBF_RX_NBF_CONFIGURATION 0x8017 // Tx no buffer, Rx no buffer, 433Mhz, 12pF
#define TX_YBF_RX_YBF_CONFIGURATIOT 0x80D7 // Tx yes buffer, Rx yes buffer, 433Mhz, 12pF
#define TX_NBF_RX_NBF_CONFIGURATION 0x8017 // Tx no buffer, Rx no buffer, 433Mhz, 12pF
#define TX_YBF_RX_YBF_CONFIGURATIOT 0x80D7 // Tx yes buffer, Rx yes buffer, 433Mhz, 12pF
// *** Power management setting - 2009sep21
#define SWITCH_POWER_ON_EVERYTHING 0xFE
#define OPERATION_MASK 0x00A0 // to clear old selection
#define TRANSMITTER_OPERATION 0x0020 // to operate as TX, switch on TX circuits
#define RECEIVER_OPERATION 0x00A0 // switch on RF front end, baseband, synthesizer, oscillator
#define TRANSMITTER_OPERATION 0x0020 // to operate as TX, switch on TX circuits
#define RECEIVER_OPERATION 0x00A0 // switch on RF front end, baseband, synthesizer, oscillator
// *** Notes on Contorl bit er ***
// Function - Enables the whole receiver chain [and starts receiving]
// Related Circuits - RF front end, baseband, synthesizer, oscillator
// Function - Enables the whole receiver chain [and starts receiving]
// Related Circuits - RF front end, baseband, synthesizer, oscillator
// *** Notes on Contorl bit et ***
// Function - Switches on the PLL, the power amplifier, and starts the
// transmission (If TX register is enabled)
// Related Circuits - Power amplifier, synthesizer, oscillator
// Warning !!! - this bit must also be set FOR RECEIVER operation!!!
// Reference - Hope RF12B Power Management Command
// Function - Switches on the PLL, the power amplifier, and starts the
// transmission (If TX register is enabled)
// Related Circuits - Power amplifier, synthesizer, oscillator
// Warning !!! - this bit must also be set FOR RECEIVER operation!!!
// Reference - Hope RF12B Power Management Command
// *** Power management setting - 2009aug08 (swap Tx Rx defines)
// #define TRANSMITTER_OPERATION 0x827E // select transmitter, enable clock o/p
// #define RECEIVER_OPERATION 0x82FE // select receiver, enable clock o/p
// #define RECEIVER_OPERATION 0x82FE // select receiver, enable clock o/p
// *** Configuration setting - old
#define ENABLE_RX_FIFO_MODE 0x0040 // b6 (= DISABLE_RX_FIFO_BUFFER 0x0040)
#define ENABLE_TX_REGISTER_AND_NIRQ_OUTPUT 0x0080 // b7
#define ENABLE_TX_REGISTER_AND_NIRQ_OUTPUT 0x0080 // b7
#define BAND_SELECT_MASK 0x0018 // b5 b4
#define BAND_433MHZ 0x0008
#define CRYSTAL_LOAD_CAPACITOR_SELECT_MASK 0x000F // b3 b2 b1 b0
#define CRYSTAL_LOAD_CAPACITOR_12_PF 0x0007
#define BAND_433MHZ 0x0008
#define CRYSTAL_LOAD_CAPACITOR_SELECT_MASK 0x000F // b3 b2 b1 b0
#define CRYSTAL_LOAD_CAPACITOR_12_PF 0x0007
#define ENABLE_TX_BUFFER 0x0080 // set el =1
#define ENABLE_RX_FIFO_BUFFER 0x0040 // set ef =1
#define ENABLE_RX_FIFO_BUFFER 0x0040 // set ef =1
// *** Power management setting - old
#define ENABLE_BASE_BAND_CLOCK_POWER 0x0040 // b6
#define ENABLE_RECEIVER_POWER 0x0080 // b7
#define ENABLE_RECEIVER_POWER 0x0080 // b7
#define SELECT_RECEIVER_POWER 0x82D7 // b6
#define SELECT_TRANSMITTER_AND_BASEBAND_CLOCK_POWER 0x8237 // b7
#define SELECT_TRANSMITTER_AND_BASEBAND_CLOCK_POWER 0x8237 // b7
#define SELECT_RECEIVER_OPERATION 0x82D7 // b6
// *** TxbRxfifo Configuration setting - 2009aug10
#define TX_YBF_RX_NBF_CONFIGURATION 0x8097 // Tx yes buffer, Rx no buffer, 433Mhz, 12pF
#define TX_NBF_RX_NBF_CONFIGURATION 0x8017 // Tx no buffer, Rx no buffer, 433Mhz, 12pF
#define TX_YBF_RX_YBF_CONFIGURATIOT 0x80D7 // Tx yes buffer, Rx yes buffer, 433Mhz, 12pF
#define TX_NBF_RX_NBF_CONFIGURATION 0x8017 // Tx no buffer, Rx no buffer, 433Mhz, 12pF
#define TX_YBF_RX_YBF_CONFIGURATIOT 0x80D7 // Tx yes buffer, Rx yes buffer, 433Mhz, 12pF
#define TX_BUFFER_RX_FIFO_CONFIGURATION 0x80D7 // Tx with buffer, Rx with IFOF, 433Mhz, 12pF
#define ENABLE_RX_POWER 0x0080 //
#define DISABLE_RX_FIFO_BUFFER 0x0040 //
#define DATA_RATE_MASK 0x00FF
#define DISABLE_RX_FIFO_BUFFER 0x0040 //
#define DATA_RATE_MASK 0x00FF
#define KHZ0024 0x0090
#define KHZ0048 0x0047
#define KHZ0096 0x0023
#define KHZ0048 0x0047
#define KHZ0096 0x0023
// *** TxbRxfifo Power management setting - 2009aug10
// #define TRANSMITTER_OPERATION 0x827E // select transmitter, enable clock o/p
// #define RECEIVER_OPERATION 0x82FE // select receiver, enable clock o/p
// #define RECEIVER_OPERATION 0x82FE // select receiver, enable clock o/p
// #define TX_BUFFER_OPERATION 0x827E // select transmitter, enable clock o/p
// #define RX_FIFO_OPERATION 0x82FE // select receiver, enable clock o/p
// #define RX_FIFO_OPERATION 0x82FE // select receiver, enable clock o/p
#endif
// RFM12B40.cpp tlfong 2009dec04hkt1430
#include "WProgram.h"
#include "RFM12B40.h"
#include "RFM12B40.h"
// *****************************************************************************
// System and initialization
// *****************************************************************************
// System and initialization
// *****************************************************************************
RFM12B40::RFM12B40(int sckPin, int sdoPin, int sdiPin, int csPin, int nIrqPin)
{
_sckPin = sckPin;
_sdoPin = sdoPin;
_sdiPin = sdiPin;
_csPin = csPin;
_nIrqPin = nIrqPin;
{
_sckPin = sckPin;
_sdoPin = sdoPin;
_sdiPin = sdiPin;
_csPin = csPin;
_nIrqPin = nIrqPin;
_commands[0] = 0x8008;
_commands[1] = 0x8208;
_commands[2] = 0xA680;
_commands[3] = 0xC623;
_commands[4] = 0x9080;
_commands[5] = 0xC22C;
_commands[6] = 0xCA80;
_commands[7] = 0xCED4;
_commands[8] = 0xB000;
_commands[9] = 0xC4F7;
_commands[10] = 0x9800;
_commands[11] = 0xCC67;
_commands[12] = 0xBA88;
_commands[13] = 0xE196;
_commands[14] = 0xC80E;
_commands[15] = 0xC000;
_commands[16] = 0x0000;
_commands[1] = 0x8208;
_commands[2] = 0xA680;
_commands[3] = 0xC623;
_commands[4] = 0x9080;
_commands[5] = 0xC22C;
_commands[6] = 0xCA80;
_commands[7] = 0xCED4;
_commands[8] = 0xB000;
_commands[9] = 0xC4F7;
_commands[10] = 0x9800;
_commands[11] = 0xCC67;
_commands[12] = 0xBA88;
_commands[13] = 0xE196;
_commands[14] = 0xC80E;
_commands[15] = 0xC000;
_commands[16] = 0x0000;
configArduinoPins();
// setupRfm12bHope10();
}
// setupRfm12bHope10();
}
void RFM12B40::configArduinoPins()
{
digitalWrite(_sckPin, LOW);
digitalWrite(_sdoPin, LOW);
digitalWrite(_csPin, LOW);
{
digitalWrite(_sckPin, LOW);
digitalWrite(_sdoPin, LOW);
digitalWrite(_csPin, LOW);
pinMode(_sckPin, OUTPUT);
pinMode(_sdoPin, OUTPUT);
pinMode(_csPin, OUTPUT);
pinMode(_sdoPin, OUTPUT);
pinMode(_csPin, OUTPUT);
pinMode(_sdiPin, INPUT);
pinMode(_nIrqPin, INPUT);
}
pinMode(_nIrqPin, INPUT);
}
void RFM12B40::testArduinoPins(int xCount, int xTime)
{
pinMode(_sckPin, OUTPUT);
pinMode(_sdoPin, OUTPUT);
pinMode(_csPin, OUTPUT);
{
pinMode(_sckPin, OUTPUT);
pinMode(_sdoPin, OUTPUT);
pinMode(_csPin, OUTPUT);
int i;
for (i = 0; i < xCount; i++)
{
digitalWrite(_sckPin, HIGH);
digitalWrite(_sdoPin, HIGH);
digitalWrite(_csPin, HIGH);
delay(xTime);
for (i = 0; i < xCount; i++)
{
digitalWrite(_sckPin, HIGH);
digitalWrite(_sdoPin, HIGH);
digitalWrite(_csPin, HIGH);
delay(xTime);
digitalWrite(_sckPin, LOW);
digitalWrite(_sdoPin, LOW);
digitalWrite(_csPin, LOW);
delay(xTime);
}
}
digitalWrite(_sdoPin, LOW);
digitalWrite(_csPin, LOW);
delay(xTime);
}
}
void RFM12B40::putWord(unsigned int xWord)
{
int i;
digitalWrite(_csPin, LOW);
digitalWrite(_sckPin, LOW);
{
int i;
digitalWrite(_csPin, LOW);
digitalWrite(_sckPin, LOW);
for(i = 0; i < 16; i++)
{
if (xWord & 0x8000)
digitalWrite(_sdoPin, HIGH); // if MSB (most significant bit) is 1 then prepare to output HIGH
else
digitalWrite(_sdoPin, LOW); // else output LOW
{
if (xWord & 0x8000)
digitalWrite(_sdoPin, HIGH); // if MSB (most significant bit) is 1 then prepare to output HIGH
else
digitalWrite(_sdoPin, LOW); // else output LOW
digitalWrite(_sckPin, HIGH); // clock high to output bit
digitalWrite(_sckPin, LOW); // clock low to get ready for next bit
digitalWrite(_sckPin, LOW); // clock low to get ready for next bit
xWord <<= 1; // shift next bit to MSB position
}
digitalWrite(_csPin, HIGH); // execute command
}
}
digitalWrite(_csPin, HIGH); // execute command
}
// *****************************************************************************
// Changing external mcu clock frequency
// *****************************************************************************
// Changing external mcu clock frequency
// *****************************************************************************
void RFM12B40::enableExternalMcuClock()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_EXTERNAL_MCU_CLOCK; // actually crystal oscillator
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_EXTERNAL_MCU_CLOCK; // actually crystal oscillator
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::setupClockFrequency(int xFrequency)
{
_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER] &= ~(EXTERNAL_MCU_CLOCK_MASK);
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER]);
_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER] |= xFrequency;
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER]);
}
{
_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER] &= ~(EXTERNAL_MCU_CLOCK_MASK);
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER]);
_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER] |= xFrequency;
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR_AND_MICROCONTROLLER_CLOCK_DIVIDER]);
}
void RFM12B40::testExternalMCUclock()
{
enableExternalMcuClock();
{
enableExternalMcuClock();
int i;
for (i = 0; i < 10; i++) {
setupClockFrequency(MHZ0100);
delay(1000);
setupClockFrequency(MHZ0125);
delay(1000);
for (i = 0; i < 10; i++) {
setupClockFrequency(MHZ0100);
delay(1000);
setupClockFrequency(MHZ0125);
delay(1000);
setupClockFrequency(MHZ0166);
delay(1000);
delay(1000);
setupClockFrequency(MHZ0200);
delay(1000);
delay(1000);
setupClockFrequency(MHZ0250);
delay(1000);
delay(1000);
setupClockFrequency(MHZ0330);
delay(1000);
delay(1000);
setupClockFrequency(MHZ0500);
delay(1000);
delay(1000);
setupClockFrequency(MHZ1000);
delay(1000);
}
}
delay(1000);
}
}
// *****************************************************************************
// Interrupts
// *****************************************************************************
// Interrupts
// *****************************************************************************
void RFM12B40::clearInterrupt()
{
putWord(CLEAR_INTERRUPT); // clear interrupt by reading status
}
{
putWord(CLEAR_INTERRUPT); // clear interrupt by reading status
}
// *****************************************************************************
// Wake up timer
// *****************************************************************************
// Wake up timer
// *****************************************************************************
void RFM12B40::enableWakeUpTimer()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_WAKE_UP_TIMER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_WAKE_UP_TIMER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::disableWakeUpTimer()
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_WAKE_UP_TIMER); // disable timer
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_WAKE_UP_TIMER); // disable timer
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::setupWakeUpTimer(int xTimePeriod)
{
putWord(xTimePeriod);
}
{
putWord(xTimePeriod);
}
void RFM12B40::calibrateWakeUpTimer(int xTimePeriod)
{
disableWakeUpTimer();
clearInterrupt();
setupWakeUpTimer(xTimePeriod);
enableWakeUpTimer();
}
{
disableWakeUpTimer();
clearInterrupt();
setupWakeUpTimer(xTimePeriod);
enableWakeUpTimer();
}
void RFM12B40::setWakeUpTimer(int xTimePeriod)
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_WAKE_UP_TIMER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
putWord(xTimePeriod);
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_WAKE_UP_TIMER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_WAKE_UP_TIMER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
putWord(xTimePeriod);
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_WAKE_UP_TIMER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::testSetupWakeUpTimer2MilliSeconds()
{
while (true)
{
disableWakeUpTimer();
clearInterrupt();
setupWakeUpTimer(MILLI_SECONDS_0002);
enableWakeUpTimer();
delay(10);
}
}
{
while (true)
{
disableWakeUpTimer();
clearInterrupt();
setupWakeUpTimer(MILLI_SECONDS_0002);
enableWakeUpTimer();
delay(10);
}
}
void RFM12B40::testWakeUpTimer(int xTime1, int xTime2)
{
while (1)
{
disableWakeUpTimer();
clearInterrupt();
setWakeUpTimer(xTime1);
delay(xTime2);
}
}
{
while (1)
{
disableWakeUpTimer();
clearInterrupt();
setWakeUpTimer(xTime1);
delay(xTime2);
}
}
void RFM12B40::testWakeUpTimer0210()
{
testWakeUpTimer(MILLI_SECONDS_0002, 10); // 2mS wake up every 10mS
}
{
testWakeUpTimer(MILLI_SECONDS_0002, 10); // 2mS wake up every 10mS
}
// *****************************************************************************
// Set up low battery detector
// *****************************************************************************
// Set up low battery detector
// *****************************************************************************
void RFM12B40::enableLowBatteryDetector()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_LOW_BATTERY_DETECTOR;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_LOW_BATTERY_DETECTOR;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::disableLowBatteryDetector()
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_LOW_BATTERY_DETECTOR);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_LOW_BATTERY_DETECTOR);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::setLowBatteryVoltageLevel(int xLowBatteryVoltage)
{
_commands[COMMAND_LOW_BATTERY_DETECTOR] &= ~(LOW_BATTERY_DETECTOR_MASK); // clear setting
_commands[COMMAND_LOW_BATTERY_DETECTOR] |= xLowBatteryVoltage; // set value
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR]); // execute instruction
}
{
_commands[COMMAND_LOW_BATTERY_DETECTOR] &= ~(LOW_BATTERY_DETECTOR_MASK); // clear setting
_commands[COMMAND_LOW_BATTERY_DETECTOR] |= xLowBatteryVoltage; // set value
putWord(_commands[COMMAND_LOW_BATTERY_DETECTOR]); // execute instruction
}
void RFM12B40::testLowBatteryDetectorV28()
{
disableLowBatteryDetector();
clearInterrupt();
enableLowBatteryDetector();
setLowBatteryVoltageLevel(VOLT_0280);
}
{
disableLowBatteryDetector();
clearInterrupt();
enableLowBatteryDetector();
setLowBatteryVoltageLevel(VOLT_0280);
}
// *****************************************************************************
// Configurations
// *****************************************************************************
void RFM12B40::configRfm12bSoftwareDefault()
{
putWord(0x0000); // ***** is this needed? tlfong 2009jul18
putWord(0x80D7); //enable tx, rx fifo, 433MHz, 12.0pF
putWord(0x8239); //enable xmitt, syn, xtal, disable clk // *** ext mcu clk disabled!
putWord(0xA640); //operation frequency ???
putWord(0xC647); //data rate 4.8kbps
putWord(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
putWord(0xC2AC); //clk rec auto, digi fltr,DQD4
putWord(0xCA81); //fifo8,sync 1, sync, no fifo fill
putWord(0xCED4); //sync pattern d4
putWord(0xC483); //offset VDI hi, no restrict, afc, afc out
putWord(0x9850); //90kHz, max o/p pwr (odBm)
putWord(0xCC17); //10MHz, 620uA, disable pll dit, 256kbps
putWord(0xE000); //wake up timer not used
putWord(0xC800); //low duty cycle not used
putWord(0xC040); //1.66MHz,2.2V low battery
}
{
putWord(0x0000); // ***** is this needed? tlfong 2009jul18
putWord(0x80D7); //enable tx, rx fifo, 433MHz, 12.0pF
putWord(0x8239); //enable xmitt, syn, xtal, disable clk // *** ext mcu clk disabled!
putWord(0xA640); //operation frequency ???
putWord(0xC647); //data rate 4.8kbps
putWord(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
putWord(0xC2AC); //clk rec auto, digi fltr,DQD4
putWord(0xCA81); //fifo8,sync 1, sync, no fifo fill
putWord(0xCED4); //sync pattern d4
putWord(0xC483); //offset VDI hi, no restrict, afc, afc out
putWord(0x9850); //90kHz, max o/p pwr (odBm)
putWord(0xCC17); //10MHz, 620uA, disable pll dit, 256kbps
putWord(0xE000); //wake up timer not used
putWord(0xC800); //low duty cycle not used
putWord(0xC040); //1.66MHz,2.2V low battery
}
void RFM12B40::configRfm12bHardwareDefault()
{
int i;
for (i=0; i < 17; i++)
{
putWord(_commands[i]);
}
}
{
int i;
for (i=0; i < 17; i++)
{
putWord(_commands[i]);
}
}
// *****************************************************************************
// Setting up non FIFO receiver mode and change data rates (2.4, 4.8, 9.6 KHz)
// *****************************************************************************
void RFM12B40::enableRxFifoMode()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RX_FIFO_MODE;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RX_FIFO_MODE;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::disableRxFifoMode()
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_RX_FIFO_MODE);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_RX_FIFO_MODE);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::enableBaseBandClockPower()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_BASE_BAND_CLOCK_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_BASE_BAND_CLOCK_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::disableBaseBandClockPower()
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_BASE_BAND_CLOCK_POWER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_BASE_BAND_CLOCK_POWER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::enableReceiverPower()
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RECEIVER_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RECEIVER_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::disableReceiverPower()
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_RECEIVER_POWER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(ENABLE_RECEIVER_POWER);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
}
void RFM12B40::enableNonFifoReceiverMode()
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
}
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
}
void RFM12B40::testReceiverClock2400Hz()
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC68E); // 2.428 KHz
}
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC68E); // 2.428 KHz
}
void RFM12B40::testReceiverClock4800Hz()
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC647); // 4.856 KHz
}
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC647); // 4.856 KHz
}
void RFM12B40::testReceiverClock9600Hz()
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC623); // 9.852 KHz
}
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
putWord(0xC623); // 9.852 KHz
}
void RFM12B40::setupDataRate2400Hz()
{
putWord(0xC68E);
}
{
putWord(0xC68E);
}
void RFM12B40::setupDataRate4800Hz()
{
putWord(0xC647);
}
{
putWord(0xC647);
}
void RFM12B40::setupDataRate9600Hz()
{
putWord(0xC623); // POR (Power on reset default is 0xC623)
}
{
putWord(0xC623); // POR (Power on reset default is 0xC623)
}
void RFM12B40::testDataRateCycle()
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
while (true)
{
setupDataRate2400Hz(); delay(4000);
setupDataRate4800Hz(); delay(4000);
setupDataRate9600Hz(); delay(4000);
}
}
{
putWord(0x8097); // Disable receiver fifo mode
putWord(0x82F9); // enable receiver power, baseband clock power
while (true)
{
setupDataRate2400Hz(); delay(4000);
setupDataRate4800Hz(); delay(4000);
setupDataRate9600Hz(); delay(4000);
}
}
void RFM12B40::setNonFifoRxAndDataRate(int xDataRate) // tlfong01 2009sep21hkt0950
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RX_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
{
_commands[COMMAND_POWER_MANAGEMENT] |= ENABLE_RX_POWER;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(DISABLE_RX_FIFO_BUFFER);
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
_commands[COMMAND_DATA_RATE] = 0xC600;
_commands[COMMAND_DATA_RATE] &= ~(DATA_RATE_MASK); // clear data rate
_commands[COMMAND_DATA_RATE] |= xDataRate; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
_commands[COMMAND_DATA_RATE] &= ~(DATA_RATE_MASK); // clear data rate
_commands[COMMAND_DATA_RATE] |= xDataRate; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
void RFM12B40::setNonFifoBufferRxRegisterBufferTxMode() // TL Fong 2009sep21hkt1745
{
// *** Configuration Setting ***
// el = 0 for non FIFO buffered RX operation
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(ENABLE_RX_FIFO_BUFFER);
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(ENABLE_RX_FIFO_BUFFER);
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
// ef = 1 for register buffered TX operation ***
_commands[COMMAND_CONFIGURATION_SETTING] |= (ENABLE_TX_BUFFER);
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
// *** Power management ***
_commands[COMMAND_POWER_MANAGEMENT] |= SWITCH_POWER_ON_EVERYTHING;
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
// *** Set Default Data rate 4.8KHz ***
_commands[COMMAND_DATA_RATE] &= ~(DATA_RATE_MASK); // clear data rate
_commands[COMMAND_DATA_RATE] |= KHZ0048; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
_commands[COMMAND_DATA_RATE] |= KHZ0048; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
// *********************************************************************************
// *********************************************************************************
// *********************************************************************************
void RFM12B40::setNonFifoBufferRxNonRegisterBufferTxMode() // TL Fong 2009sep21hkt1745
{
// *** Configuration Setting ***
{
// *** Configuration Setting ***
// el = 0 for non FIFO buffered RX operation
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(ENABLE_RX_FIFO_BUFFER); // disable RX FIFO
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(ENABLE_RX_FIFO_BUFFER); // disable RX FIFO
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
// ef = 0 for non register buffered TX operation ***
_commands[COMMAND_CONFIGURATION_SETTING] &= ~(ENABLE_TX_REGISTER_BUFFER); // disable TX Register
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
putWord(_commands[COMMAND_CONFIGURATION_SETTING]); // execute instruction
// *** Power management ***
_commands[COMMAND_POWER_MANAGEMENT] |= SWITCH_POWER_ON_EVERYTHING; // (receiver operation by default)
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
putWord(_commands[COMMAND_POWER_MANAGEMENT]);
// *** Set External MCU Clock 5 MHz ***
enableExternalMcuClock();
setupClockFrequency(MHZ0500);
setupClockFrequency(MHZ0500);
// *** Set Default Data rate 4.8KHz ***
_commands[COMMAND_DATA_RATE] &= ~(DATA_RATE_MASK); // clear data rate
_commands[COMMAND_DATA_RATE] |= KHZ0048; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
_commands[COMMAND_DATA_RATE] |= KHZ0048; // set data rate
putWord(_commands[COMMAND_DATA_RATE]); // execute instruction
}
// *********************************************************************************
// *********************************************************************************
// *********************************************************************************
void RFM12B40::selectOperation(int xOperation)
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(OPERATION_MASK); // clear selection
_commands[COMMAND_POWER_MANAGEMENT] |= xOperation; // select transmitter or receiver
putWord(_commands[COMMAND_POWER_MANAGEMENT]); // execute instruction
}
{
_commands[COMMAND_POWER_MANAGEMENT] &= ~(OPERATION_MASK); // clear selection
_commands[COMMAND_POWER_MANAGEMENT] |= xOperation; // select transmitter or receiver
putWord(_commands[COMMAND_POWER_MANAGEMENT]); // execute instruction
}
// *****************************************************************************
// Transmitting bytes B01010101 non stop
// *****************************************************************************
void RFM12B40::selectTransmitterAndBaseBandClockPower()
{
putWord(SELECT_TRANSMITTER_AND_BASEBAND_CLOCK_POWER);
}
{
putWord(SELECT_TRANSMITTER_AND_BASEBAND_CLOCK_POWER);
}
void RFM12B40::transmitByte(byte xByte)
{
int nIrqPinStatus = LOW;
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + xByte);
}
{
int nIrqPinStatus = LOW;
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + xByte);
}
void RFM12B40::testTransmitBytesNonStop01()
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
while (true)
{
transmitByte(0xAA); // 8 bits / 9600 bits/sec == 1 mS/byte
delay(10);
}
}
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
while (true)
{
transmitByte(0xAA); // 8 bits / 9600 bits/sec == 1 mS/byte
delay(10);
}
}
void RFM12B40::testTransmitBytesNonStop01a()
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
while (true)
{
transmitByte(0x5A);
delay(10);
}
}
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
while (true)
{
transmitByte(0x5A);
delay(10);
}
}
void RFM12B40::testTransmitBytesNonStop02(int betweenCharactersDelay)
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
// setupDataRate9600Hz();
while (true)
{
transmitByte(0xAA); // 8 bits / 9600 bits/sec == 1 mS/byte
delay(betweenCharactersDelay);
}
}
void RFM12B40::testTransmitBytesNonStop04()
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate2400Hz();
int nIrqPinStatus = HIGH;
putWord(0x0000); // reset interrupt
putWord(0x0000); // reset interrupt
while (true)
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
void RFM12B40::testTransmitBytesNonStop04a()
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
int nIrqPinStatus = HIGH;
putWord(0x0000); // reset interrupt
putWord(0x0000); // reset interrupt
while (true)
{
putWord(0xB800 + 0x00C3);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
{
putWord(0xB800 + 0x00C3);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
void RFM12B40::testTransmitBytesNonStop05()
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate9600Hz();
int nIrqPinStatus = HIGH;
putWord(0x0000); // reset interrupt
putWord(0x0000); // reset interrupt
while (true)
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + 0x003C);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
void RFM12B40::testTransmitBytesNonStop06() // tlfong 2009sep23hkt1243
{
enableNonFifoReceiverMode();
selectTransmitterAndBaseBandClockPower();
setupDataRate4800Hz();
int nIrqPinStatus = HIGH;
putWord(0x0000); // reset interrupt
putWord(0x0000); // reset interrupt
while (true)
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
{
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + 0x003C);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + 0x0055);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(10);
}
}
// *****************************************************************************
// Receiving bytes B01010101 non stop
// *****************************************************************************
void RFM12B40::resetRfm12bInterrupt()
{
putWord(0x0000); // reset interrupt
}
{
putWord(0x0000); // reset interrupt
}
void RFM12B40::configTxBufferedRxNonFifoMode()
{
putWord(0x8097);
}
{
putWord(0x8097);
}
void RFM12B40::switchPowerOnEverything()
{
putWord(0x82FE);
}
{
putWord(0x82FE);
}
void RFM12B40::changeTransceiverToNonFifoReceiver()
{
putWord(0x82FE); // switch on everything
}
{
putWord(0x82FE); // switch on everything
}
void RFM12B40::changeTransceiverToBufferedTransmitter()
{
putWord(0x827E); // switch on everything except Receiver er = 0
}
{
putWord(0x827E); // switch on everything except Receiver er = 0
}
void RFM12B40::testBufferedTransmitter01()
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate4800Hz();
changeTransceiverToBufferedTransmitter();
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate4800Hz();
changeTransceiverToBufferedTransmitter();
int nIrqPinStatus = HIGH;
resetRfm12bInterrupt();
while (true)
{
putWord(0xB800 + 0x5A);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
resetRfm12bInterrupt();
delay(10);
}
}
resetRfm12bInterrupt();
while (true)
{
putWord(0xB800 + 0x5A);
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
resetRfm12bInterrupt();
delay(10);
}
}
void RFM12B40::testNonFifoReceiver01()
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate4800Hz();
changeTransceiverToNonFifoReceiver();
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate4800Hz();
changeTransceiverToNonFifoReceiver();
while (true)
{
}
}
{
}
}
void RFM12B40::testNonFifoReceiver04a()
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate9600Hz();
changeTransceiverToNonFifoReceiver();
{
configTxBufferedRxNonFifoMode();
switchPowerOnEverything();
setupDataRate9600Hz();
changeTransceiverToNonFifoReceiver();
while (true)
{
}
}
{
}
}
// *****************************************************************************
// No Buffer Tx, No Buffer Rx tests
// *****************************************************************************
void RFM12B40::selectTransmitterNoBufferReceiverNoBufferConfiguration()
{
putWord(TX_NBF_RX_NBF_CONFIGURATION);
}
{
putWord(TX_NBF_RX_NBF_CONFIGURATION);
}
void RFM12B40::selectTransmitterOperation()
{
putWord(TRANSMITTER_OPERATION);
}
{
putWord(TRANSMITTER_OPERATION);
}
void RFM12B40::selectReceiverOperation()
{
putWord(RECEIVER_OPERATION);
}
{
putWord(RECEIVER_OPERATION);
}
// *****************************************************************************
// Tx Buffer, Rx FIFO test - 2009aut10hkt1237mon
// *****************************************************************************
void RFM12B40::selectTxbRxfifoConfig()
{
putWord(TX_BUFFER_RX_FIFO_CONFIGURATION);
}
{
putWord(TX_BUFFER_RX_FIFO_CONFIGURATION);
}
void RFM12B40::selectTxbOperation()
{
// putWord(TX_BUFFER_OPERATION);
}
{
// putWord(TX_BUFFER_OPERATION);
}
void RFM12B40::selectRxfifoOperation()
{
// putWord(RX_FIFO_OPERATION);
}
{
// putWord(RX_FIFO_OPERATION);
}
void RFM12B40::xmitByte01(byte xByte)
{
int nIrqPinStatus = LOW; // uln2003 inverts nIRQ level
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + xByte);
delay(100); // too long?
}
{
int nIrqPinStatus = LOW; // uln2003 inverts nIRQ level
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
putWord(0xB800 + xByte);
delay(100); // too long?
}
void RFM12B40::xmitPacket01()
{
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
{
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
xmitByte01(0x2D); // sync word 1
xmitByte01(0xD4); // sync word 2
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0xD4); // sync word 2
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0x55); // data byte
xmitByte01(0xAA); // CRC
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
}
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
xmitByte01(0xAA); // preamble
}
void RFM12B40::recvPacket02()
{
putWord(0x0000); // reset interrupt
int nIrqPinStatus = LOW; // uln2003A inverts nIRQ level
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(100); // too long?
}
{
putWord(0x0000); // reset interrupt
int nIrqPinStatus = LOW; // uln2003A inverts nIRQ level
while (nIrqPinStatus == LOW)
{
nIrqPinStatus = digitalRead(_nIrqPin);
}
putWord(0x0000); // reset interrupt
delay(100); // too long?
}
void RFM12B40::testTxB01()
{
while (true)
{
xmitPacket01();
delay(500);
}
}
void RFM12B40::testRxFifo01()
{
// dummy
}
{
while (true)
{
xmitPacket01();
delay(500);
}
}
void RFM12B40::testRxFifo01()
{
// dummy
}
// *****************************************************************************
// End
// *****************************************************************************
.END
No comments:
Post a Comment