Today, we are going to start first part of new serie of articles about wireless data loggers. Today, we will do simple temperature logger for short periods. This temperature logger uses TMP112 device assembled on DCTR module and stores value into MCU EEPROM.
As you can read in documentation, NODE EEPROM is directly accessible via DPA protocol from coordinator. So, If you store something to EEPROM, you can use simple DPA packet to read it:
- NADR: 0x0001
- PNUM: 0x03 (EEPROM)
- PCMD: 0x00 (READ BYTE)
- HWPID: 0xFFFF
- DATA: 0x10, 0x04 (START ADDR: 0x10, no of bytes: 0x04)
Now, you need some custom DPA handler for node device. So let’s do it.
Temperature logger node device
We can use source code from this post as base for our new DPA Custom handler, because we need timer6 interrupt for measurement timing. If “can_record” flag is set “do_record” flag is set every 5sec.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | // If TMR6 interrupt occurred if ( TMR6IF ) { // Unmask interrupt TMR6IF = 0; if (cntr > 0) { cntr -= 1; } else { // Decrement counts cntr = 500-1; // = 5sec if (can_record) do_record = 1; } } |
Temperature measurement and storage is done in DpaEvent_Idle event:
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | case DpaEvent_Idle: // Do a quick background work when RF packet is not received if (do_record == 1) { if (eep_addr<100) { temp = getTemperature(); // store temperature eeWriteByte(EEPROM_DATA_OFFSET + eep_addr,temp); // increment eeprom data index eep_addr+=1; // store eeprom data index eeWriteByte(EEPROM_INDEX,eep_addr); } else { can_record = 0; } do_record = 0; pulseLEDG(); } break; |
If “do_record” flag is set, and number of records (eep_addr) is lower than 100, temperature conversion is executed and value is stored inside MCU internal EEPROM. If number of record is 100, then “can_record” is cleared and data logger is stopped. Every conversion and data storage is indicated by green LED.
Now, let see, how data logger is executed and stopped:
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | // Handle peripheral command if ( _PNUM == PNUM_USER + 0 ) // ? { // Check command if ( _PCMD == 1 ) { // Check data length if ( _DpaDataLength != 0 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); eep_addr = 0; do_record = 1; can_record = 1; goto DpaHandleReturnTRUE; } if ( _PCMD == 0 ) { // Check data length if ( _DpaDataLength != 0 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); eep_addr = 0; do_record = 0; can_record = 0; goto DpaHandleReturnTRUE; } DpaApiReturnPeripheralError( ERROR_PCMD ); } |
As you can see, you can use two DPA packets to control temperature logger:
- NADR: 0x0001
- PNUM: 0x20 (TEMP LOGGER)
- PCMD: 0x01 (RE-START)
- HWPID: 0xFFFF
- DATA: —-
and
- NADR: 0x0001
- PNUM: 0x20 (TEMP LOGGER)
- PCMD: 0x01 (STOP)
- HWPID: 0xFFFF
- DATA: —-
Testing
If you (re)start and stop temperature logger after 20 seconds, you will have four records of temperature inside EEPROM. Additional, you will have stored EEPROM index. EEPROM index is stored at address 0x00. Temperature is stored from address 0x10. So for EEPROM index readout use this DPA packet:
- NADR: 0x0001
- PNUM: 0x03 (EEPROM)
- PCMD: 0x00 (READ BYTE)
- HWPID: 0xFFFF
- DATA: 0x00, 0x01
For temperature readout use:
- NADR: 0x0001
- PNUM: 0x03 (EEPROM)
- PCMD: 0x00 (READ BYTE)
- HWPID: 0xFFFF
- DATA: 0x10, 0x04 (START ADDR: 0x10, no of bytes: 0x04)
You should get something like:

temp logger DPA response
In this case, four numbers represents temperatures: 28°C, 28°C, 27°C, 27°C.
This simple temperature logger has a lot of limitations. The biggest one is small number of possible records. During the following days, I am going to prepare another article, where external EEPROM (EEEPROM) will be used for data storage.
Full source code is attached.