beals.william

SensorTile: Auto Log on power-up

Blog Post created by beals.william on Apr 6, 2018

All:

 

I have been tinkering with the SensorTile to use as-is for some data logging applications.  It wasn't my original intent, but it turned out to be so handy as-is I didn't see a need to make something ground-up for my very limited application.

 

For this application the double-tap to start/stop didn't make sense, I wanted the device to start logging upon turning on and then log until I switched the device off.  To make this work reliably, I made the following changes:

 - Always create a new sequence number in the log file

 - Start logging on power-up

 - Flush the file system caches on every write so at most one data sample is lost on power down.

 

See the post titled "SensorTile SD Card Data Logger filename improvement" for the changes on ensuring each time a log file is created, it is a new sequence number.  The standard code always starts at 000 on every power-up, erasing anything previous.  This checks for already existing filenames and finds the first available serial number (well, up to 999 files anyway).

 

Attached below is the modified main.c to start logging on power-up.  To do this I created the #define LOGALWAYS near the top.  While unrelated, I also created the ACC_RANGE #define to increase the accellerometer range.  Too many changes, so just posting the updated main.c.  Look for wmb: for my changes to the standard 1.3.1 distribution

 

To minimize data loss, add the code below to the file datalog_application.c on/about line 171, in the routine DATALOG_SD_writeBuf() right after the f_write() function.  This flushes the data written to the SD card so that when power is finally removed, any data written up to that point is safely on the SD card. Bit iffy, but works quite well.

 

  /* wmb: do a sync to avoid any data loss due to error conditions, abort if problems */
  if(f_sync(&MyFile) != FR_OK)
  {
    return 0;
  }

 

Hope someone finds this helpful.

 

will

Attachments

Outcomes