
One use for an embedded system is for it to sit off somewhere recording values from sensors or other external sources. An example of this would be a weather station where rain fall, wind speed and cloud cover etc can be monitored. A useful function for a data logger such as this would be to allow for the data to be output in a way that is easily removed from the system to be used later, stored or further processed by a computer.
Using the EB037 MMC card reader E-block it is possible to write sensor values directly to a MMC or SD card into a format that is instantly recognised by a computer. MMC and SD cards have to be formatted to use a file structure before they can hold data. The Flowcode FAT16 component can only read and write to cards that are formatted to the FAT16 file standard. To do this you can insert the card into a computer, right click the card and select "Format...." making sure that the file system is set to FAT or FAT16. Note : make sure you have backed up any data from the card before formatting. The FAT16 component is a little resource hungry so it will not work with PIC12 and PIC16 series devices this is due to problems allocating the 512 byte sector buffer, more on this later.
The Flowcode FAT16 component is still in a beta stage so it must be invoked via the Flowcode custom component. To do this, simply copy the Custom_Code.C file into your Flowcode V3/Components directory. The component can then be added to your Flowcode program by clicking on the custom component icon marked β€userβ€. Connections to the EB037 MMC card reader E-block are configured by clicking on the menu on the custom component and selecting properties from the list. The create time and date are simple constants that define the creation time and date of the files.

Data_Logger_Simple_Slow
The first example file will create a file onto the MMC/SD card named β€log1.csvβ€. If the file already exists on the card then an error message will be displayed. After the file has been created the program enters a loop, which takes a sample from ADC channel 0 and then writes the value to the card in the following format β€Sample_Value, β€. Once the samples have been written to the card it can be removed from the embedded system and inserted into a computer where the analogue values will load straight into Microsoft Excel. As each sample performs an individual write to the disk this method of recording samples can be a little slow especially if you wish to achieve high-speed sampling rates.
Data_logger_Sector_Fast
Each file on the card is made up of a number of disk sectors. Each sector is 512 bytes wide so therefore the minimum physical file size is always 512 bytes. Therefore to increase the productivity of the program it is possible to write the entire 512 byte sector to the card in one command. This time the entire 512 byte buffer is filled by taking 128 samples. Each sample is formatted into a string so that it is 3 characters wide with a fourth character to hold the comma. Therefore 128 x 4 bytes = 512 bytes or one disk sector. The example fills 5 complete sectors with ADC samples, which again can be opened straight into Microsoft Excel. Again if the file name β€log2.csvβ€ already exists on the disk then the program will return an error.