A month ago, we tested simple temperature logger with EEPROM storage. Today, we are going to do some improvements. We will use external EEPROM – EEEPROM for data storage (128×16 positions) and EEPROM as settings storage. In addition we will make a sampling period adjustable by DPA command.
We will continue in sense of previous post, but we will save only 16 values of temperature to EEPROM. When we have 16 values, we will move them to EEEPROM. And again…
if (do_record == 1) { if (eeep_addr<EEEPROM_INDEX_MAX) { // temperature conversion temp = getTemperature(); // temperature storage eeWriteByte(EEPROM_DATA_OFFSET + eep_addr,temp); // eeprom index increment eep_addr+=1; // eeprom index storage eeWriteByte(EEPROM_INDEX,eep_addr); // pulse LED R pulseLEDR(); // eeprom --> eeeprom if (eep_addr == 16) { // read data from eeprom eeReadData(EEPROM_DATA_OFFSET + 0, 16); // save data to eeeprom eeeWriteData((uns16)eeep_addr*16); // eeprom a eeeprom index change eep_addr = 0; eeep_addr +=1; eeWriteByte(EEPROM_INDEX,eep_addr); eeWriteByte(EEEPROM_INDEX,eeep_addr); // pulse LED G pulseLEDG(); } } ... |
Similarly, I changed timing of temperature sampling. Now timing is variable by the user command (log_period). Changed line is highlighted.
if ( TMR6IF ) { // Unmask interrupt TMR6IF = 0; if (cntr > 0) { cntr -= 1; } else { // Decrement counts cntr = ((uns16)log_period*100)-1; if (can_record) do_record = 1; } } |
Also, we have new command for user peripheral. _PCMD = 0x02. Period is limited between 1 sec and 60 sec (minute). There is request handler for this case:
// Check command if ( _PCMD == CMD_SET_PERIOD ) { // Check data length if ( _DpaDataLength != 1 ) DpaApiReturnPeripheralError( ERROR_DATA_LEN ); // allows 1-60 only if (_DpaMessage.Response.PData[0]<1) DpaApiReturnPeripheralError( ERROR_DATA ); if (_DpaMessage.Response.PData[0]>60) DpaApiReturnPeripheralError( ERROR_DATA ); log_period = _DpaMessage.Response.PData[0]; eeWriteByte(PERIOD_INDEX,log_period); goto DpaHandleReturnTRUE; } |
Examples of DPA packets:
- NADR: 0x01; PNUM: 0x20; PCMD: 0x01; HWPID: 0xFFFF – Start log
- NADR: 0x01; PNUM: 0x20; PCMD: 0x00; HWPID: 0xFFFF – Stop log
- NADR: 0x01; PNUM: 0x20; PCMD: 0x02; HWPID: 0xFFFF; DATA: 0x05 – set period to 5sec.
Log reading
You can read both EEPROM and EEEPROM contents directly from IQRF:
- NADR: 0x01
- PNUM: 0x03 (EEPROM)
- PCMD: 0x00 (READ)
- HWPID: 0xFFFF (GENERAL HWPID)
- DATA: 0x00, 0x03 (start address 0, data len: 3)
- NADR: 0x01
- PNUM: 0x04 (EEEPROM)
- PCMD: 0x00 (READ)
- HWPID: 0xFFFF (GENERAL HWPID)
- DATA: 0x00, 0x10 (start address 0, data len: 16)
Full source code is attached.