element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog Create an IoT system with FRDM-K64F - Part 2 : Sensor SD Datalogger
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 17 Mar 2015 1:27 AM Date Created
  • Views 433 views
  • Likes 2 likes
  • Comments 1 comment
  • fxos8700cq
  • frdm-k64f
  • datalogger
Related
Recommended

Create an IoT system with FRDM-K64F - Part 2 : Sensor SD Datalogger

bheemarao
bheemarao
17 Mar 2015

Here is a project created to interface 6-axis sensor FXOS8700 and storing its data on SD card together act as data logger using K64F freedom board.


Refer to my earlier blogs which i have created separately on interfacing FXOS8700 sensor present onboard with K64 board where i have explained clearly on creating the required components for this activity using KDS + Processor expert

[FRDM-K64F + Kinetis Design Studio (KDS)+Processor Expert(PE)] Interfacing inbuilt 6-axis sensor FXOS8700 and displaying the data on terminal

 

And one more project on exploring the SD card interface and Accessing SD card and writing some data into it using KDS + Processor expert.

[FRDM-K64F + Kinetis Design Studio (KDS)+Processor Expert(PE)] Accessing SDCARD through K64 board


Here in this tutorial i am integrating or combining both the projects and created newer one in order to act as a Data logger project which stores the sensor data to SD card.


Before we start this project below are the pre-requisites:

  1. KDS software tool from Freescale
  2. FRDM-K64F Freedom development board
  3. Micro-SD-Card ( I am using 1GB)


Here is an explanation of the project creation:

I have created the project with the name “K64 Sensor+SDcard” the components of this project are as shown below:


image

 

  1. FAT_FileSystem
  2. TimerInt
  3. FXOS8700CQ
  4. Utility
  5. LEDR-BitIO
  6. LEDG-BitIO
  7. ConsoleIO


And there are few reference components which are dependant or linked to components.

Details about these components have been provided in the earlier blogs (links given above)


Below are the lines of code for initialising the FXOS registers.

     if (FX1_WriteReg8(FX1_CTRL_REG_1, 0x00) != ERR_OK) {

               return ERR_FAILED;

            }

       if (FX1_WriteReg8(FX1_M_CTRL_REG_1, 0x1F) != ERR_OK) {

               return ERR_FAILED;

            }

       if (FX1_WriteReg8(FX1_M_CTRL_REG_2, 0x20) != ERR_OK) {

               return ERR_FAILED;

            }

        if (FX1_WriteReg8(FX1_XYZ_DATA_CFG, 0x00) != ERR_OK) {

               return ERR_FAILED;

            }

        if (FX1_WriteReg8(FX1_CTRL_REG_1, 0x0D) != ERR_OK) {

               return ERR_FAILED;

            }

The below function call FX1_GetX() will get the accelerometer values.

x = FX1_GetX();

y = FX1_GetY();

z = FX1_GetZ();

printf("Accelerometer value \tX: %4d\t Y: %4d\t Z: %4d\n",x,y,z);


and the below function collects the magnetometer values:

if (FX1_GetMagX(&magX)!=ERR_OK) {

                     return ERR_OK;

                  }

if (FX1_GetMagY(&magY)!=ERR_OK) {

                            return ERR_OK;

                         }

if (FX1_GetMagZ(&magZ)!=ERR_OK) {

                            return ERR_OK;

                         }

printf("Magnetometer value \tX: %4d\t Y: %4d\t Z: %4d\n",magX,magY,magZ);


There is a function LogToFile() in Application.c folder which does our task of storing the data to SD-card as shown below:

 

LogToFile(x, y, z);

LogToFile(magX,magY,magZ);

This function uses FAT component and opens a file called log.txt and append to its last edited part and writes the sensor values i.e x,y,z or magX,magY,magZ depending on the function call.

 

static void LogToFile(int16_t x, int16_t y, int16_t z) {

      uint8_t write_buf[48];

      UINT bw;

      TIMEREC time;

 

      /* open file */

      if (FAT1_open(&fp, "./log.txt", FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) {

        Err();

      }

      /* move to the end of the file */

      if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) {

        Err();

      }

      /* get time */

      if (TmDt1_GetTime(&time)!=ERR_OK) {

        Err();

      }

      /* write data */

      write_buf[0] = '\0';

      UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Hour);

      UTIL1_chcat(write_buf, sizeof(write_buf), ':');

      UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Min);

      UTIL1_chcat(write_buf, sizeof(write_buf), ':');

      UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Sec);

      UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

 

      UTIL1_strcatNum16s(write_buf, sizeof(write_buf), x);

      UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

      UTIL1_strcatNum16s(write_buf, sizeof(write_buf), y);

      UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

      UTIL1_strcatNum16s(write_buf, sizeof(write_buf), z);

      UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\r\n");

      if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) {

        (void)FAT1_close(&fp);

        Err();

      }

      /* closing file */

      (void)FAT1_close(&fp);

      }

 

Now i am connecting the SD-card to K64 board as shown below and follow these steps:

image

 

 

  1. Build and compile the project
  2. Open a hyper terminal (Putty in my case) with proper ‘com’ port number (CDC usb port) which is created after connecting your board to PC
  3. Set a Baud rate of 9600 bps
  4. Execute the project
  5. For every 1 sec the sensor data is displayed on the terminal and also stored in “Log.txt” file created in SD-card


The output seen on the terminal is as shown below:


image

 

Opening the log file shows the stored SD card data:

image

 

 

I have enclosed the *.SREC file, you can download this and test it directly by programming the binaries.

and also the project folder for your quick reference.


Happy Dataloging with SD-card image image image

Attachments:
  • Sign in to reply
  • Former Member
    Former Member over 10 years ago

    Nice blog, very handy. I have written another blog on data logging using an alternative way by making use of the latest KSDK 1.2.0 and Processor Expert. Hope this one can help others as well. See my blog at: FRDM K64F Data Logger using FatFs with KSDK 1.2.0 | Centaurian

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube