Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SD CARD wants

Status
Not open for further replies.

AtomSoft

Well-Known Member
THIS PIC WILL BE CONTROLLED FROM ANOTHER MCU meaning its a SLAVE so you can use a smaller PIC or ARM or what ever you want that has UART available to control a SD card. Kind of like a DOSonCHIP... they canceled it tho.

Im using a 18F4620 since its perfect heh... I wanted to know what kind of features should be added

Get directory listing
, Returns 2 byte count then Names followed by a CR byte
Read data from a file, SEND: Filename,Start,Len) returns BYTES and CR byte
Write data to a file SEND: Filename,Len returns PASS or FAIL
Append data to a file (Filename,Start,Len) same as above.

I know i can do this without issue just asking for extra advice on functions you think might be useful.
 
It would be easiest to check what other types of SD access chips like this supported. They have datasheets available for them. Or even check what functions FAT file system libraries give you and replicate those.

This is the V1 datasheet for DOSonChip. They went to a binary command system on V2.
https://www.electro-tech-online.com/custompdfs/2011/07/CD17B10_User_Guide_0v1.pdf

uALFAT:
https://www.electro-tech-online.com/custompdfs/2011/07/uALFAT20Manual.pdf

USBWiz:
https://www.electro-tech-online.com/custompdfs/2011/07/USBwiz20Library20Manual.pdf
1.3.2 _INCLUDE_FAT_SYSTEM_SUPPORT_
If defined the following functions are available:
int8 GHI_MountFATFileSystem(int8 device);
int8 GHI_SwitchDevice(int8 device);
int8 GHI_ChangeDirectory(int8* filename);
int8 GHI_MakeDirectory(int8* filename);
int8 GHI_OpenFile(int8 filehandle, int8 *filename, int8 openmode);
int8 GHI_SendReadCommand(int8 filehandle, int32 desireddatasize, int8 filler);
int8 GHI_SendWriteCommand(int8 filehandle, int32 desireddatasize);
int8 GHI_GetReadAndWriteResult(int32 * actualdatasize);
int8 GHI_CloseFile(int8 filehande);
int8 GHI_DeleteFile(int8 *filename);

1.3.3 _INCLUDE_EXTENDED_FAT_SYSTEM_SUPPORT_
If defined the following functions are available:
void GHI_StartMediaStatistics (void);
int8 GHI_GetResultMediaStatistics(int32 * size, int32 * free);
void GHI_StartQformat(void);
int8 GHI_InitGetFile(void);
int8 GHI_GetNextFile(int8 * file_name, int8 * file_ext, int8 * attributes, int32 *
size);
int8 GHI_RemoveDirectory(int8* filename);
int8 GHI_SendReadWriteFileCommand(int8 readhandle, int8 writehandle, int32
size);
int8 GHI_SendShadowWriteTwoFiles(int8 firstfilehandle, int8 secondfilehandle,
int32 desireddatasize);
int8 GHI_GetShadowWriteTwoFileResults(int8 *fresult1, int8 *fresult2, int32
*writtendata1, int32 *writtendata2);
int8 GHI_SendShadowWriteThreeFiles(int8 firstfilehandle, int8 secondfilehandle,
int8 thirdfilehandle, int32 desireddatasize);
int8 GHI_GetShadowWriteThreeFileResults(int8 *fresult1, int8 *fresult2, int8
*fresult3, int32 *writtendata1, int32 *writtendata2, int32 *writtendata3);
int8 GHI_SeekFile(int8 filehandle, int32 newposition);
int8 GHI_GetPointerPosition(int8 filehandle, int32 *sector, int16
*positioninsector);
int8 GHI_SplitFile(int8 sourcehandle, int8 desthandle1, int8 desthandle2, int32
splitposition, int32 * actualdestsize1, int32 * actualdestsize2);
int8 GHI_FlushFile(int8 filehandle);
int8 GHI_GetFileInfo(int8 *filename, int32 *size, int8 *attributes, int32
*TimeDate);
int8 GHI_RenameFile(int8 *filename,int8 *newname);
int8 GHI_SetFileSize(int8 filehandle,int32 newsize);
 
Last edited:
The raw directory listing is good, but a search function would be valuable. The average user doesn't care what the entire contents of a directory are, just if a certain file is there or not. This can be coded by hand of course from the raw directory listing, but an inbuilt function to do this would make it FAR more useful to newbs.

Does this support both fat16 and fat32?
 
Thanks for both the inputs :D

Too many functions Mark :D i plan to make this simpler not that heavy. When REV 1 is done i will release full SOURCE. This isnt a money thing so its free for ALL!!! based on a 18F4620 but can be modded of course. So far i have the SD card working well on it and UART using interrupts is so cool!

Sceadwian thats a great idea! i can add that no problem im sure. You can use FAT16/FAT32 and SDHC compatible! Will be cool to see what other people add. Im working on some functions now.. the main stuff and adding comments as i go along so the code isnt too scary. I hope this will be a useful thing for the community :D

One thing i would love to try and add is a simple FORMAT option. Will look into boot sectors and such. I will have 2 options a QUICK and a FULL. Quick will just act like its empty ... the normal windows way :D and full will clear out everything! it will open every sector and erase whats not needed... but this is still just a thought. Id have to learn a bit more..

The REV 1 should be done by MONDAY tops!
 
Last edited:
They been using MINIX format for SD cards over at Jal it makes better sense it has a lot faster read write times then fat
 
be8, how can the file system type change read/write access speeds?
 
OMG the way PIC handles memory sucks!

I cant seem to send one string to another funtion.

This is in my MAIN function:
Code:
	if(strncmp(CMD[LIST],RX_CMD,4) == 0)	//Send out directory listing
	{
		res = scan_files(RX_ARG);
		return;
	}

Now i know for a fact that RX_ARG is 128 bytes long and containes "/" only the rest are zeros. Why in the world when i pass it to
Code:
scan_files(RX_ARG);

It says its 0x0101

This is the function:
Code:
FRESULT scan_files (char* path);

I dont have this issue with the EXACT same ARM code so i assume its a stupid PIC thing... Can someone pls help me out... thanks
 

Attachments

  • ScreenA.jpg
    ScreenA.jpg
    166.6 KB · Views: 159
Last edited:
It was made for slow Cpu 8 and 16 And i no for fact using MINIX on some old hardware the disk writes are faster them fat 16 or 32
I just started looking into this when they added it to Jal libs. Jal has Hd support and SD using the Minix file sys. now and it looks real good.

A MINIX file system has six components:[1]

The Boot Block which is always stored in the first block. It contains the boot loader that loads and runs an operating system at system startup.
The second block is the Superblock which stores data about the file system, that allows the operating system to locate and understand other file system structures. For example, the number of inodes and zones, the size of the two bitmaps and the starting block of the data area.
The inode bitmap is a simple map of the inodes that tracks which ones are in use and which ones are free by representing them as either a one (in use) or a zero (free).
The zone bitmap works in the same way as the inode bitmap, except it tracks the zones
The inodes area. Each file or directory is represented as an inode, which records metadata including type (file, directory, block, char, pipe), ids for user and group, three timestamps that record the date and time of last access, last modification and last status change. An inode also contains a list of addresses that point to the zones in the data area where the file or directory data is actually stored.
The data area is the largest component of the file system, using the majority of the space. It is where the actual file and directory data are stored.

With Fat there a lot of fat to read to find the data you want
 
MINIX on some old hardware the disk writes are faster them fat 16 or 32
What does that have to do with a modern micro controller running on flash memory? The slowness you're talking about may have been a physical limitation of the older hardware.
 
Ok figured it was showing memory address now it has the correct one at least

EDIT: Also i forgot

Code:
#include <stdio.h>

for the sprintf :D
 
Last edited:
Here is a update so far:

Commands:
LIST - LIST ALL FILES AND DIRECTORY WITH A COUNT
READ - WORKING ON IT
WRITE - WORKING ON IT
APPEND - WORKING ON IT
LIST_FILES - LIST FILES ONLY WITH COUNT
LIST_DIRS - LIST DIRs ONLY WITH COUNT

It will send the count first then the data.

THE READ,WRITE,APPEND will be worked on now... then ill add more commands.

Also i have 1 pin which sets UART speed. Either 9600 or 19200... might add more later.. not sure
 
Last edited:
Ok working on READ right now...

You send the word READ with a SPACE at the end
Then 2 bytes for the position to start at MSB first with a SPACE at the end
You then send the filename with a LF at the end.

****the buffer is 128 btyes so it will try to read 128 bytes if it cannot because of end of file it will stop and send the count of bytes read and then the actual data.

It will then return 2 bytes MSB first for the count of bytes read ...
Then it will return the actual DATA READ from file.

If your original MCU doesnt have space for all 128 bytes simple skip them ...
 
CRAP ! i just noticed i was using the PETITE FS which doesnt support creating files. I will have to rewrite a couple things to use the normal FATFS heh but shouldnt take too long :D
 
Can someone help me out here. Running into a Syntax error and driving me crazy!!!! got a huge headache now... here is complete code so far. I dont recommend using it yet still working on a ton of things :D
 

Attachments

  • SD4620.zip
    63.3 KB · Views: 145
Now yet another error:

Code:
MPLINK 4.39, Linker
Device Database Version 1.1
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.udata_main.o' can not fit the section. Section '.udata_main.o' length=0x0000044e
Errors    : 1

This is why i switched to ARM heh so many errors
 
Im about to abandon this code and transfer to ARM.. I will most likely use the LPC1114, its Faster, cheaper(half price)

It has half the memory but double the ram ... ill check for another MCU that will also qualify. The posted code is the final code so far. Just remove the zz and it should give you the udata issue.

Kind of dont want to use LPC2103 mainly because requires 1.8v for core and 3.3v for logic... to many extra external stuff
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top