Add readTemperature() and rcCalibration()
This commit is contained in:
parent
2fb8051e3c
commit
61658a06be
|
|
@ -73,6 +73,16 @@ void loop() {
|
||||||
Serial.print("DeviceID: ");
|
Serial.print("DeviceID: ");
|
||||||
word jedecid = flash.readDeviceId();
|
word jedecid = flash.readDeviceId();
|
||||||
Serial.println(jedecid, HEX);
|
Serial.println(jedecid, HEX);
|
||||||
|
}
|
||||||
|
if (input == 't')
|
||||||
|
{
|
||||||
|
byte temperature = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient
|
||||||
|
byte fTemp = 1.8 * temperature + 32; // 9/5=1.8
|
||||||
|
Serial.print( "Radio Temp is ");
|
||||||
|
Serial.print(temperature);
|
||||||
|
Serial.print("C, ");
|
||||||
|
Serial.print(fTemp); //converting to F loses some resolution, obvious when C is on edge between 2 values (ie 26C=78F, 27C=80F)
|
||||||
|
Serial.println('F');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
31
RFM69.cpp
31
RFM69.cpp
|
|
@ -25,7 +25,7 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||||
const byte CONFIG[][2] =
|
const byte CONFIG[][2] =
|
||||||
{
|
{
|
||||||
/* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY },
|
/* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY },
|
||||||
/* 0x02 */ { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 }, //gaussian, bt=1.0
|
/* 0x02 */ { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 }, //no shaping
|
||||||
/* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, //default:4.8 KBPS
|
/* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, //default:4.8 KBPS
|
||||||
/* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_55555},
|
/* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_55555},
|
||||||
/* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, //default:5khz, (FDEV + BitRate/2 <= 500Khz)
|
/* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, //default:5khz, (FDEV + BitRate/2 <= 500Khz)
|
||||||
|
|
@ -43,7 +43,7 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||||
///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111},
|
///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111},
|
||||||
///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, //over current protection (default is 95mA)
|
///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, //over current protection (default is 95mA)
|
||||||
|
|
||||||
// RXBW defaults are {RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz)
|
// RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz)
|
||||||
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, //(BitRate < 2 * RxBw)
|
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, //(BitRate < 2 * RxBw)
|
||||||
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, //DIO0 is the only IRQ we're using
|
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, //DIO0 is the only IRQ we're using
|
||||||
/* 0x29 */ { REG_RSSITHRESH, 220 }, //must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm
|
/* 0x29 */ { REG_RSSITHRESH, 220 }, //must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm
|
||||||
|
|
@ -235,7 +235,6 @@ void RFM69::interruptHandler() {
|
||||||
select();
|
select();
|
||||||
SPI.transfer(REG_FIFO & 0x7f);
|
SPI.transfer(REG_FIFO & 0x7f);
|
||||||
PAYLOADLEN = SPI.transfer(0);
|
PAYLOADLEN = SPI.transfer(0);
|
||||||
DATALEN = PAYLOADLEN - 3;
|
|
||||||
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution
|
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution
|
||||||
TARGETID = SPI.transfer(0);
|
TARGETID = SPI.transfer(0);
|
||||||
if(!(_promiscuousMode || TARGETID==_address || TARGETID==0)) //match this node's address, or broadcast addr 0x0 or anything in promiscuous mode
|
if(!(_promiscuousMode || TARGETID==_address || TARGETID==0)) //match this node's address, or broadcast addr 0x0 or anything in promiscuous mode
|
||||||
|
|
@ -245,6 +244,7 @@ void RFM69::interruptHandler() {
|
||||||
//digitalWrite(4, 0);
|
//digitalWrite(4, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DATALEN = PAYLOADLEN - 3;
|
||||||
SENDERID = SPI.transfer(0);
|
SENDERID = SPI.transfer(0);
|
||||||
byte CTLbyte = SPI.transfer(0);
|
byte CTLbyte = SPI.transfer(0);
|
||||||
|
|
||||||
|
|
@ -258,7 +258,7 @@ void RFM69::interruptHandler() {
|
||||||
unselect();
|
unselect();
|
||||||
setMode(RF69_MODE_RX);
|
setMode(RF69_MODE_RX);
|
||||||
}
|
}
|
||||||
//digitalWrite(4, 0);
|
//digitalWrite(4, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RFM69::isr0() { selfPointer->interruptHandler(); }
|
void RFM69::isr0() { selfPointer->interruptHandler(); }
|
||||||
|
|
@ -395,15 +395,16 @@ void RFM69::readAllRegs()
|
||||||
unselect();
|
unselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
//// doesnt seem to work as expected
|
byte RFM69::readTemperature(byte calFactor) //returns centigrade
|
||||||
// byte RFM69::readTemp(bool calibrate) {
|
{
|
||||||
// if (calibrate)
|
setMode(RF69_MODE_STANDBY);
|
||||||
// {
|
writeReg(REG_TEMP1, RF_TEMP1_MEAS_START);
|
||||||
// writeReg(REG_OSC1, RF_OSC1_RCCAL_START);
|
while ((readReg(REG_TEMP1) & RF_TEMP1_MEAS_RUNNING)) Serial.print('*');
|
||||||
// while ((readReg(REG_OSC1) & RF_OSC1_RCCAL_DONE) == 0x00);
|
return ~readReg(REG_TEMP2) + COURSE_TEMP_COEF + calFactor; //'complement'corrects the slope, rising temp = rising val
|
||||||
// }
|
} // COURSE_TEMP_COEF puts reading in the ballpark, user can add additional correction
|
||||||
|
|
||||||
// writeReg(REG_TEMP1, RF_TEMP1_MEAS_START);
|
void RFM69::rcCalibration()
|
||||||
// while ((readReg(REG_TEMP1) & RF_TEMP1_MEAS_RUNNING));
|
{
|
||||||
// return readReg(REG_TEMP2);
|
writeReg(REG_OSC1, RF_OSC1_RCCAL_START);
|
||||||
// }
|
while ((readReg(REG_OSC1) & RF_OSC1_RCCAL_DONE) == 0x00);
|
||||||
|
}
|
||||||
5
RFM69.h
5
RFM69.h
|
|
@ -28,6 +28,7 @@
|
||||||
#define RF69_915MHZ 91
|
#define RF69_915MHZ 91
|
||||||
|
|
||||||
#define null 0
|
#define null 0
|
||||||
|
#define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
|
||||||
|
|
||||||
class RFM69 {
|
class RFM69 {
|
||||||
public:
|
public:
|
||||||
|
|
@ -65,6 +66,8 @@ class RFM69 {
|
||||||
void setHighPower(bool onOFF=true); //have to call it after initialize for RFM69HW
|
void setHighPower(bool onOFF=true); //have to call it after initialize for RFM69HW
|
||||||
void setPowerLevel(byte level); //reduce/increase transmit power level
|
void setPowerLevel(byte level); //reduce/increase transmit power level
|
||||||
void sleep();
|
void sleep();
|
||||||
|
byte readTemperature(byte calFactor=0); //get CMOS temperature (8bit)
|
||||||
|
void rcCalibration(); //calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy]
|
||||||
|
|
||||||
// allow hacking registers by making these public
|
// allow hacking registers by making these public
|
||||||
byte readReg(byte addr);
|
byte readReg(byte addr);
|
||||||
|
|
@ -73,7 +76,7 @@ class RFM69 {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void isr0();
|
static void isr0();
|
||||||
void interruptHandler();
|
void virtual interruptHandler();
|
||||||
void sendFrame(byte toAddress, const void* buffer, byte size, bool requestACK=false, bool sendACK=false);
|
void sendFrame(byte toAddress, const void* buffer, byte size, bool requestACK=false, bool sendACK=false);
|
||||||
|
|
||||||
static RFM69* selfPointer;
|
static RFM69* selfPointer;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue