Difference between revisions of "Component: File (SD/SDHC Card) (Storage)"
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
==File (SD/SDHC Card) component== | ==File (SD/SDHC Card) component== | ||
File component allowing access to read and write files on a SD/SDHC card. Also compatible with micro SD/SDHC cards, please note the pin layout is subtely different for these. The component automatically detects the filesystem on the card on initialise so FAT16 and FAT32 are fully supported. When used in simulation provides read/write access to files on the local windows file system. | File component allowing access to read and write files on a SD/SDHC card. Also compatible with micro SD/SDHC cards, please note the pin layout is subtely different for these. The component automatically detects the filesystem on the card on initialise so FAT16 and FAT32 are fully supported. When used in simulation provides read/write access to files on the local windows file system. | ||
+ | |||
+ | ==Component Pack== | ||
+ | |||
+ | STORAGE | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 22: | Line 34: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 84: | Line 104: | ||
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT |
| width="90%" | NumBytes | | width="90%" | NumBytes | ||
|- | |- | ||
Line 336: | Line 356: | ||
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] - | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 445: | Line 465: | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''UpdateFileSector''' | ||
+ | |- | ||
+ | | colspan="2" | Updates a file sector with new data set from using WriteByteToBuffer. Note this cannot alter the size of the file. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 504: | Line 537: | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 531: | Line 551: | ||
|- | |- | ||
|- | |- | ||
− | + | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | |
− | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | | width="10%" align="center" style="background-color:# | ||
− | | width="90%" style="background-color:# | ||
|- | |- | ||
|- | |- | ||
Line 600: | Line 590: | ||
| colspan="2" | SPI high speed clock divider - Once startup is complete this is the rate that will be used to transfer data | | colspan="2" | SPI high speed clock divider - Once startup is complete this is the rate that will be used to transfer data | ||
|- | |- | ||
− | | width="10%" align="center" style="background-color:# | + | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] |
− | | width="90%" style="background-color:# | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | File System |
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Max Concurrent Files | ||
+ | |- | ||
+ | | colspan="2" | Specifies how many concurrent files can be opened at any one time. Use the SetFileIndex macro to switch between concurrent files. | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | End Of File | ||
+ | |- | ||
+ | | colspan="2" | Specifies the way the ReadByteFromFile function indicates the end of a file. 8 Bit mode - End of the file is represented by the value 0, read multiple times to confirm that the 0 is not simply data. 16 Bit mode - End of file is represented by the value 512 allowing the values 0 - 255 to represent valid data. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation | ||
|- | |- | ||
|- | |- | ||
Line 613: | Line 617: | ||
|- | |- | ||
| colspan="2" | Defines the simulation type. The default is to use the Windows file system to allow for reading and writing files. The alternative is to use the CAL functionality to allow the SPI transactions to be passed onto a seperate handler e.g. for logging or debugging purposes. | | colspan="2" | Defines the simulation type. The default is to use the Windows file system to allow for reading and writing files. The alternative is to use the CAL functionality to allow the SPI transactions to be passed onto a seperate handler e.g. for logging or debugging purposes. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | File System | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-20-icon.png]] | ||
+ | | width="90%" | Root Directory | ||
+ | |- | ||
+ | | colspan="2" | Directory flagged as root for simulation Default: $(srcdir) is the current project source directory. Modern windows systems do not like you writing files to a hard drive root directory so a directory off the root is advised. | ||
|} | |} |
Latest revision as of 17:20, 9 November 2022
Author | Matrix Ltd. |
Version | 3.0 |
Category | Storage |
Contents
File (SD/SDHC Card) component
File component allowing access to read and write files on a SD/SDHC card. Also compatible with micro SD/SDHC cards, please note the pin layout is subtely different for these. The component automatically detects the filesystem on the card on initialise so FAT16 and FAT32 are fully supported. When used in simulation provides read/write access to files on the local windows file system.
Component Pack
STORAGE
Detailed description
No detailed description exists yet for this component
Examples
Reading data from a text file
Example to read a text file from a SD card or from a text file in simulation and display on a 16 x 2 character LCD. The text file needs to be in the same directory as the Flowcode .fcfx project file for the simulation to run correctly.
FAT Read File
File:Test.txt
Console showing current 512 byte sector data
Console showing high level FAT status
Parsing a standard .BMP image file
Example to read a bitmap image file from a SD card or from a bitmap file in simulation and display on a graphical LCD. The bitmapfile needs to be in the same directory as the Flowcode .fcfx project file for the simulation to run correctly.
FAT display Bitmap
Demo bitmap files referenced in the example.
Picture showing a bitmap being displayed on a GLCD component.
Data logger Simple
Example showing how to take a collection of analogue readings and save them into a text based file, the simple way.
FAT data logger simple but slow
Data logger Advanced
Example showing how to take a collection of analogue readings and save them into a text based file, the fast way.
FAT data logger fast
Log Keypad Presses
Example showing how to poll a keypad for key presses. Each key press is shown on an LCD and appended to a log file as an ASCII character using the FAT component.
Keypad Press Log
Streaming Audio Files
Example showing how to steam out .wav audio files from an SD card using a 16-bit @ 16KHz file format. A free program such as Audacity can be used to create or edit the .wav files.
WAV Streaming
Downloadable macro reference
![]() |
WriteByteToBuffer |
Writes a single byte to the current 512 byte local sector buffer. | |
![]() |
Address |
Address Range 0 - 511 | |
![]() |
Data |
Data Byte to write to the buffer | |
![]() |
Return |
![]() |
CloseFile |
Closes the current open file | |
![]() |
Return |
![]() |
DeleteFile |
Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success. | |
![]() |
Filename |
8.3 format filename e.g."file.txt" | |
![]() |
Return |
![]() |
SetFileIndex |
Sets the current file index and used to switch between several open file streams. Default = 0. | |
![]() |
File_Index |
File index ranges from 0 to (Max Concurrent Files - 1) | |
![]() |
Return |
![]() |
SetByte |
![]() |
Int |
![]() |
Ix |
![]() |
Value |
![]() |
Return |
![]() |
ReadFileSize |
Reads the entire size of the current file in bytes. | |
![]() |
Return |
![]() |
UpdateFileSector |
Updates a file sector with new data set from using WriteByteToBuffer. Note this cannot alter the size of the file. | |
![]() |
Return |
![]() |
GetByte |
Gets a byte from an int | |
![]() |
Int |
![]() |
Ix |
![]() |
Return |
![]() |
SetTimeAndDate |
Sets the current time and date. Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat | |
![]() |
Time |
Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2 | |
![]() |
Date |
Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980 | |
![]() |
Return |
![]() |
Initialise |
Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 for success. | |
![]() |
Return |