Data log for logging enviornmental, process and system state to FRAM or EPROM chips that do not have support for a file system. Includes support for multiple record types, evolving record types, automatic date and time stamp and copying contents to serial. Will soon support journaling to micro SD file system. We always log to fram first for speed and power conserfaction then copy in bulk to SD cards when we have charging power available.
Flexible Data Logger Example Use and Test Code
Detailed Documentation
See home page for data log library https://developer.mbed.org/users/joeata2wh/code/data_log/
License
By Joseph Ellsworth CTO of A2WH Take a look at A2WH.com Producing Water from Air using Solar Energy March-2016 License: https://developer.mbed.org/handbook/MIT-Licence Please contact us http://a2wh.com for help with custom design projects.
Revision 7:3886935f9364, committed 2016-09-15
- Comitter:
- joeata2wh
- Date:
- Thu Sep 15 18:33:56 2016 +0000
- Parent:
- 6:26e862e19be2
- Commit message:
- This version works with STM Nucleo F303K8 but SB16,SB18 must be removed to allow I2C and SPI to work simultaneously on that board
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Mar 31 22:15:35 2016 +0000 +++ b/main.cpp Thu Sep 15 18:33:56 2016 +0000 @@ -6,6 +6,29 @@ Take a look at A2WH.com Producing Water from Air using Solar Energy March-2016 License: https://developer.mbed.org/handbook/MIT-Licence Please contact us http://a2wh.com for help with custom design projects. + + When using F303K8 and I2C + SB16 and SB18 must be removed because + they link D4 to A4 and D5 to A5 + PG #12 http://www.st.com/content/ccc/resource/technical/document/user_manual/e3/0e/88/05/e8/74/43/a0/DM00231744.pdf/files/DM00231744.pdf/jcr:content/translations/en.DM00231744.pdf + + FRAM Chip Interface MB85RS2MTPH-G-JNE1 + 3 MBit FRAM. Also works with WinBond W25Q80BV and Windbond 8MB chips. + + #1 - Chip Select + #2 - DO - Data Out hook to MISO + #3 - WP - Write Protect - connect GND + #4 - GND + #5 - DI - Data In - hook to MOSI + #6 - CLk- Clock - Hook to SPI_SCLK + #7 - HD - Hold - connect VCC 3.3V + #8 - VCC - Connect VCC 3.3V + + See Also: http://www.instructables.com/id/How-to-Design-with-Discrete-SPI-Flash-Memory/step2/The-WinBond-Device-Interface/ + + If system seems to return garbage after writting test data + then one or more pins are most likely linked with a solder bridge + check the users guide for the board you are using. */ #include "mbed.h" @@ -21,17 +44,18 @@ #define dataLogMISOPin SPI1_MISO #define dataLogMOSIPin SPI1_MOSI #define dataLogCLKPin SPI1_SCK -#define dataLogSelectPin PC_12 +#define dataLogSelectPin PA_4 //#define DO_LOG_ERASE // uncomment to erase the existing log. //#define DO_SEND_MANUAL // uncomment to send first 1000 bytes to pc on startup //#define DO_SEND_ALL // uncomment to send entire log to PC on startup -//#define DO_SEND_LAST // uncomment to sent last 900 bytes to pc on startup +//#define DO_SEND_LAST // uncomment to send last 900 bytes to pc on startup +//#define TEST_BASIC_READ_WRITE // uncomment to erase chip and test basic read write interface AnalogIn waterTempSense(A0); AnalogIn oxygenLevelSense(A1); AnalogIn solarStrengthSense(A2); -AnalogIn waterSpeedSense(A3); + // imagine for sake of example that we have // circuitry that actually convert these Volt // readings to useful readings. @@ -54,10 +78,10 @@ float waterTemp = waterTempSense.read() * adc_ref; float oxygenLevel = oxygenLevelSense.read() * adc_ref; float solarStrength = solarStrengthSense.read() * adc_ref; - float waterSpeed = waterSpeedSense.read() * adc_ref; + //float waterSpeed = waterSpeedSense.read() * adc_ref; char tbuff[256]; - sprintf(tbuff, "%0.2f,%0.2f,%0.2f,%0.2f", waterTemp, oxygenLevel, solarStrength,waterSpeed); + sprintf(tbuff, "%0.2f,%0.2f,%0.2f", waterTemp, oxygenLevel, solarStrength); dlLog(lgr, "sensors",tbuff); // date and time are automatically recorded with the call. // time is only recorded to the second granularity and dates @@ -102,10 +126,23 @@ char dlbuff[81]; // buffer used internally by this instance of data log DataLogChipType dlchip(dataLogMOSIPin, dataLogMISOPin, dataLogCLKPin, dataLogSelectPin); pc.printf("\r\nInitialized Data Log Chip"); - struct DLOG *lgr = dlMake(&dlchip, dlbuff, 80, &pc); + + #ifdef TEST_BASIC_READ_WRITE + printf("start basic write test\r\n"); + printf("chipErase\r\n"); + dlchip.chipErase(); + memset(dlbuff,0,30); + memcpy(dlbuff, "I am a test\r\n\r\n\r\n",17); + dlchip.writeStream(100,dlbuff, 17); + memset(dlbuff,0,30); + dlchip.readStream(100, dlbuff, 17); + printf("read buffer =%s\r\n", dlbuff); + #endif + + struct DLOG *lgr = dlMake(&dlchip, dlbuff, 80, &pc); pc.printf("\r\nInitialized Logger\r\n"); - pc.printf("logger nextWritePos=%ld", lgr->nextWritePos); + pc.printf("logger nextWritePos=%ld", lgr->nextWritePos); dlHelp(lgr); // send data log command help to pc. #ifdef DO_LOG_ERASE