FAT Keeps Returning 255

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Benj wrote:Hi Rocket,

Hmm is the sect bytes error returning on all the cards your trying or are you only testing a single card? What about if you format the card using different cluster sizes. Finally was the card working previously?

Very odd as my PIC version is working for all cards and we have ported the code to dsPIC and this is also working very nicely :(
Hello Ben,

Here are the cards I have tested:

SanDisk 128MB
Pretec 2GB
SanDisk 4GB

For each one, I have tried FAT and FAT32. Yes, I did change the FAT component mode to the appropriate format (FAT or FAT32). Every card and format returns a sector bytes error. I am not able to change the cluster sizes because the only available size is "Default Allocation Size". The SanDisk 128MB SD and the Pretec 2GB SD has worked with the FCV4 FAT component flawlessly. I never tested the SanDisk 4GB with FCV4 because it was SDHC. If we can't figure this out, I think I will purchase a logic analyzer so I can really see what is going on.

Thanks again,
Henry

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Do you have any thoughts?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hi Rocket,

Sorry I'm not ignoring you. I have lots of thoughts but not sure how relevant they are. I will have another go to try and replicate your setup and see if I hit the same issue. A card that was working in v4 should certainly be working with the newer code, the same goes (hopefully) for cards that were not working in v4.

I will press on and let you know how i'm getting on. Thing is i'm also working on an MIAC Android project for a show which is high priority so I don't have as much time for testing as usual. Anyway it's on my list and I will see what I can do for you ASAP.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Benj wrote:Hi Rocket,

Sorry I'm not ignoring you. I have lots of thoughts but not sure how relevant they are. I will have another go to try and replicate your setup and see if I hit the same issue. A card that was working in v4 should certainly be working with the newer code, the same goes (hopefully) for cards that were not working in v4.

I will press on and let you know how i'm getting on. Thing is i'm also working on an MIAC Android project for a show which is high priority so I don't have as much time for testing as usual. Anyway it's on my list and I will see what I can do for you ASAP.
Sorry, I didn't mean to be persistent. Take your time. I just wasn't sure if you saw my post or not.

Thanks,

Henry

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: FAT Keeps Returning 255

Post by JohnCrow »

Hi
I've also had problems with getting some types of card to work under FC5.
I have now put the latest component into my FC5.4 installation. These are my findings

Formatted as FAT16-default allocation
These all work fine.

Verbatim-Class2-2GB
Sandisk-Class2-2Gb
Kingstone-Class2-2GB-MicroSD in adaptor
Team-Class2-2GB-MicroSD in adpator
Panssonic-Class4-2GB
Texet-Class6-4GB

Formatted as FAT32-default allocation
Verbatim-Class4-8GB

These were all tested on an ECIO40 with the card reader on PortA and the LCD on Port B
Using Software Mode.
FAT 16 Test File
Create_open_write-works-softwaremode-ecio.fcf
(9.5 KiB) Downloaded 320 times
FAT32 Test File
Create_open_write-works-softwaremode-ecio32.fcf
(9.5 KiB) Downloaded 291 times
Hope this information is of help
If Henry would like to post his test file I can try it on my hardware and memory cards. I only have cards in the sizes shown above.
The new component certainly seems to be working fine here
I think I will purchase a logic analyzer so I can really see what is going on .
I can recommend the Matrix Test Pod. Great bit of kit and well work the money.
1 in 10 people understand binary, the other one doesn't !

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hello,

Right I have just tried the AVR component as posted on page 1 of this topic and I once got the sect bytes err when hot plugging the card but since then it is starting up correctly every time.

I am currently using the software SPI so I will switch to hardware and test again.

File Removed - Newer version below

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hello,

Using the Hardware SPI I am constantly getting the Init Fail 237 - Sect bytes error so it must be something to do with this.

I will have a play and see if I can solve it. For now you should be able to use the software SPI mode to get the FAT component working.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

If I comment out this line from the MX_Init_Card function then the hardware SPI also works.

Code: Select all

%a_SPI_Set_Prescaler(1);

Code: Select all

//%a_SPI_Set_Prescaler(1);
So it looks like the SPI comms is ok but the speed change is causing issues on AVR. I will see if I can get this fixed.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Right here we go here is the semi official release for the new and improved FAT component.
FC5_GENERIC_FAT16.c
(59.15 KiB) Downloaded 391 times
The Generic File needs renaming to match the FAT component C file from your Components directory. Onc eyou have renamed the file copy it into the components folder replacing the file that currently exists there.
PIC_CAL_SPI.c
(13.86 KiB) Downloaded 328 times
AVR_CAL_SPI.c
(18.31 KiB) Downloaded 338 times
ARM_CAL_SPI.c
(13.46 KiB) Downloaded 313 times
The CAL file for your version of Flowcode should be copied into the "CAL/Version" folder, replacing the file that currently exists there.

For interest the updates recently added to the FAT component since the v5 release include:
  • Multiple concurrent file support allowing for multistreaming or direct file copying etc - info here http://www.matrixmultimedia.com/mmforum ... 165#p39270
  • Increased speed in hardware and software modes
  • Speed correctly ramped up after initialisation to allow card to run as fast as possible
  • SDHC support
  • Additional SD support for slower / older / awkward cards
  • Number of additional bug fixes and optimisations
I beleive there may be an outstanding bug from the component in Flowcode which means the time and date are not calculated correctly. We have fixed this and it will be included in the next release. For now I think you can fix this by using custom code on the defines macro to swap substitutions %l and %k.

Any further requests then let me know.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Benj wrote:Right here we go here is the semi official release for the new and improved FAT component.
FC5_GENERIC_FAT16.c
The Generic File needs renaming to match the FAT component C file from your Components directory. Onc eyou have renamed the file copy it into the components folder replacing the file that currently exists there.
PIC_CAL_SPI.c
AVR_CAL_SPI.c
ARM_CAL_SPI.c
The CAL file for your version of Flowcode should be copied into the "CAL/Version" folder, replacing the file that currently exists there.
You did it Ben!!! It works perfectly!!! Thank you so, so much!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

You did it Ben!!! It works perfectly!!! Thank you so, so much!
Your welcome, just glad it all works and seems stable again :D

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: FAT Keeps Returning 255

Post by JohnCrow »

The generic component is working fine on software mode for the framework of a new project working using the card reader.
Will try changing to running on hardware tomorrow as the bit of extra speed could be useful.
Watch this space.
1 in 10 people understand binary, the other one doesn't !

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: FAT Keeps Returning 255

Post by Jordy101091 »

HI all,

The past few days I've had some trouble with the FAT component.
I was not able to create files and sometimes it wont init the card.
I have changed the component files with the ones Ben has modified, But im encountering a small problem:

When I create a file (that part works), I want to write something to this file with the macro "Append String to File"
When I for example want to wright this string to the file "Hello World of SD" it never does even something simple as "test".
My text (.txt) file is allways empty does somebody know what the problem might be?

Anyway thanks allot for fixing most of the SD card problems :P

Regards Jordy
the will to learn, should not be stopped by any price

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Ben,

So I have a slight problem too. I have been playing around with the file index and so far it works perfectly for switching currently opened files to write to. But for some reason the file index won't switch the open file to the right one when reading from the card. It just stays on whatever the last file opened by the open file macro was. The index seems to have no effect on it. Weird. Do you have any idea what is going on?

Henry

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hi jordy,

Are you opening the file after you create it? Can you attach your program.

Hi henry can you please attach your prog too and I'll have a look. I tested the mechanism by reading files so it should be working.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Benj wrote:Hi jordy,

Are you opening the file after you create it? Can you attach your program.

Hi henry can you please attach your prog too and I'll have a look. I tested the mechanism by reading files so it should be working.
Hello Ben!

Attached are the files.

Henry
Attachments
multifiles1.c
(61.86 KiB) Downloaded 205 times
multifiles1.fcf_avr
(22.97 KiB) Downloaded 216 times

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: FAT Keeps Returning 255

Post by Jordy101091 »

Ben,

I have PM you my program.
I try to append a string to the file that I have created and openend
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hello Henry,

I think I can see your problem.

When you are reading back the files you are not collecting the latest buffer from the file, instead you are using the local copy of the sector buffer.

Here is your code at the moment.

set file index (0)
value = read byte from buffer (0)
portd = value

set file index (1)
value = read byte from buffer (0)
portd = value

Try changing to this instead to allow the local buffer to be refreshed.

set file index (0)
read file sector ()
value = read byte from buffer (0)
portd = value

set file index (1)
read file sector ()
value = read byte from buffer (0)
portd = value

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hi Jordy,

Thanks for the file, that's one beast of a program!

I have had a look at your program and can't seem to spot any issues with it. Any chance you can create a really basic program that simply shows the issue as this is much easier for me to test here. Possibly is because of a RAM issue but I can't test properly because I cannot compile your program due to missing custom code.

The delays between FAT functions should not be needed unless you specifically want them in your program.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: FAT Keeps Returning 255

Post by JohnCrow »

Hi Benj

The new components are working fine with PICs, but I did a quick test over the weekend with the MIAC and serial module and I still found the same problems with most of my cards (some did work). Will try more tests with this when I get a minute.

Is the card reader in the serial / gps units the same as the standard e-block?
1 in 10 people understand binary, the other one doesn't !

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hi John,

Yes the card reader circuitry is the same in the Add-on modules and thankfully the FAT firmware currently resides in the MIAC so updating to the new version should not be an issue.

We have updated the MIAC component files and they seem to also be working really well. Simply pop the attached file into your "V5/Components" directory, re-compile the program and hopefully it should all work for you.
FC5_PIC_FAT16_MS.c
(57.74 KiB) Downloaded 223 times

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: FAT Keeps Returning 255

Post by Jordy101091 »

Ben,

I have tryed your updates C code file in the hope it would work this time,
Creating a file works as aspected opening the file (dont know if this works) and appending a string to this file doesnt work.
The file is created but empty, sorry to say :cry:

I dont know if its me that does something wrong ore its the component it self.

Regards Jordy
the will to learn, should not be stopped by any price

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: FAT Keeps Returning 255

Post by JohnCrow »

Hi Benj

Thanks, just tried the card reader on the MIAC module, all works fine
1 in 10 people understand binary, the other one doesn't !

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Post by rocket200 »

Benj wrote:Hello Henry,

I think I can see your problem.

When you are reading back the files you are not collecting the latest buffer from the file, instead you are using the local copy of the sector buffer.

Here is your code at the moment.

set file index (0)
value = read byte from buffer (0)
portd = value

set file index (1)
value = read byte from buffer (0)
portd = value

Try changing to this instead to allow the local buffer to be refreshed.

set file index (0)
read file sector ()
value = read byte from buffer (0)
portd = value

set file index (1)
read file sector ()
value = read byte from buffer (0)
portd = value
That solved it! Thanks! I have one question though, is there a way to read just ONE byte from the 512 byte buffer on the SD card? Transferring the entire buffer from the SD card to the local buffer takes way too much time. I would just read off each sector buffer of my 12 files, then store them in the AVR's ram, but 6.1 kbytes is too large for the RAM. By sending just one byte per file over the SPI bus, I save a ton of time.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT Keeps Returning 255

Post by Benj »

Hello,
is there a way to read just ONE byte from the 512 byte buffer on the SD card? Transferring the entire buffer from the SD card to the local buffer takes way too much time. I would just read off each sector buffer of my 12 files, then store them in the AVR's ram, but 6.1 kbytes is too large for the RAM. By sending just one byte per file over the SPI bus, I save a ton of time.
I'm afraid the memory of the card is accessed in 512 byte sectors. I have put some thought in trying to get rid of the 512 byte buffer but I just don't think it's possible. Looking at other software FAT drivers I am yet to come across one that didn't have at least a 512 byte buffer. You could read a single byte but if you did not clock through the rest of the sector then the card would be in a non ready state when you tried to do the next operation meaning your not really saving any time anyway. Also it's not as simple as saying I want that byte as you can only address the memory via the sector address.

I still think using a PC to combine the files in some way prior to running will give you the best results.

Post Reply