Skip to content

Commit f0bab85

Browse files
authored
Merge pull request #1 from cyberman54/cyberman54-TEMPERATURE
Demo PR for issue mcci-catena#772 - add API to get temperature value of SX 127x chip
2 parents 93108f0 + 5689a94 commit f0bab85

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/lmic/oslmic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int os_init_ex (const void *pPinMap);
115115
void os_runloop (void);
116116
void os_runloop_once (void);
117117
u1_t radio_rssi (void);
118+
s1_t radio_GetRawTemp(void);
118119
void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi);
119120

120121
//================================================================================

src/lmic/radio.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,60 @@ u1_t radio_rssi () {
11761176
return r;
11771177
}
11781178

1179+
// Reads the raw temperature
1180+
// \retval New raw temperature reading in 2's complement format
1181+
s1_t radio_GetRawTemp(void) {
1182+
1183+
#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
1184+
#define RF_IMAGECAL_TEMPMONITOR_ON 0x00
1185+
#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
1186+
1187+
int8_t temp = 0;
1188+
uint8_t previousOpMode, RegTemp;
1189+
1190+
// Save current Operation Mode
1191+
previousOpMode = readReg(RegOpMode);
1192+
1193+
// Put device in FSK Sleep Mode
1194+
opmode(OPMODE_SLEEP);
1195+
1196+
// select FSK modem (from sleep mode)
1197+
opmodeFSK();
1198+
ASSERT((readReg(RegOpMode) & OPMODE_LORA) == 0);
1199+
1200+
// Put device in FSK RxSynth
1201+
opmode(OPMODE_FSRX);
1202+
1203+
// Enable Temperature reading
1204+
writeReg(FSKRegImageCal, (readReg(RegOpMode) & RF_IMAGECAL_TEMPMONITOR_MASK) |
1205+
RF_IMAGECAL_TEMPMONITOR_ON);
1206+
1207+
// Wait 150us
1208+
hal_waitUntil(os_getTime() + us2osticks(150));
1209+
1210+
// Disable Temperature reading
1211+
writeReg(FSKRegImageCal, (readReg(RegOpMode) & RF_IMAGECAL_TEMPMONITOR_MASK) |
1212+
RF_IMAGECAL_TEMPMONITOR_OFF);
1213+
1214+
// Put device in FSK Sleep Mode
1215+
opmode(OPMODE_SLEEP);
1216+
1217+
// Read temperature
1218+
RegTemp = readReg(FSKRegTemp);
1219+
1220+
if ((RegTemp & 0x80) == 0x80) {
1221+
temp = 255 - RegTemp;
1222+
} else {
1223+
temp = RegTemp;
1224+
temp *= -1;
1225+
}
1226+
1227+
// Reload previous Op Mode
1228+
writeReg(RegOpMode, previousOpMode);
1229+
1230+
return temp;
1231+
}
1232+
11791233
/// \brief get the current RSSI on the current channel.
11801234
///
11811235
/// monitor rssi for specified number of ostime_t ticks, and return statistics

0 commit comments

Comments
 (0)