FAT 16 Not Working

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

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

FAT 16 Not Working

Post by rocket200 »

Hello,

I am using flowcode v4 for AVR to program. I'm using an atmega328p for the chip. What I have been trying to do is interface a FAT 16 formatted sd card with my avr. So far have have had no luck. The sd card seems to be setup correctly because I tried it with an arduino and it seems to recognize it. All my flowcode program does is try to initiate the FAT 16 card with the FAT component. It then turns an led on if it has initiated properly. So far it is not initiating. Any ideas on what is causing this to not work?

Also there are a couple warnings I'm getting from flowcode:

C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c: In function 'FCD_FAT160_Create_File':
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:503: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:504: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:505: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:506: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:511: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:512: warning: large integer implicitly truncated to unsigned type


Thanks!!!

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: FAT 16 Not Working

Post by DavidA »

Hello,

I dont know if you are using the latest Fat component as lots of fixes went into an updated component which is available here:

http://www.matrixmultimedia.com/mmforum ... =29&t=7461

Scroll down for the PIC and AVR versions of the component.

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

Re: FAT 16 Not Working

Post by rocket200 »

DavidA wrote:Hello,

I dont know if you are using the latest Fat component as lots of fixes went into an updated component which is available here:

http://www.matrixmultimedia.com/mmforum ... =29&t=7461

Scroll down for the PIC and AVR versions of the component.
I updated the Fat component, but now it's not compiling because of some errors:

C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c: In function 'FCD_FAT160_Create_File':
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:509: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:510: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:511: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:512: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:517: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:518: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c: In function 'FCD_FAT160_MX_Init_Card':
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:845: error: expected ')' before ';' token
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:1240: error: expected declaration or statement at end of input

Error returned from [avr-gcc.exe]

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

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

Re: FAT 16 Not Working

Post by rocket200 »

Anybody? Is there more information I can provide to help figure the problem out?

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 16 Not Working

Post by Benj »

Hello,

I have just tried compiling the FAT component C file from my installation and this is working correctly.
AVR_FAT16.c
(51.99 KiB) Downloaded 308 times
Let me know how you get on.

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

I have just tried compiling the FAT component C file from my installation and this is working correctly.
AVR_FAT16.c
Let me know how you get on.
Hi,

Still getting those weird errors:

C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c: In function 'FCD_FAT160_Create_File':
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:663: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:664: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:665: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:666: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:671: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:672: warning: large integer implicitly truncated to unsigned type
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c: In function 'FCD_FAT160_MX_Init_Card':
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:1023: error: expected ')' before ';' token
C:\DOCUME~1\HENRYB~1\Desktop\Flowcode1.c:1503: error: expected declaration or statement at end of input

Error returned from [avr-gcc.exe]

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: FAT 16 Not Working

Post by DavidA »

Hello,

Does your Flowchart contain any C code?

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

Re: FAT 16 Not Working

Post by rocket200 »

DavidA wrote:Hello,

Does your Flowchart contain any C code?
My Flowchart does not contain any C code.

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: FAT 16 Not Working

Post by DavidA »

Hello,

Would it be possible for you to post your fcf file here

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

Re: FAT 16 Not Working

Post by rocket200 »

DavidA wrote:Hello,

Would it be possible for you to post your fcf file here
Sure! I also attached the compiled C code if that helps any.
Attachments
SD Project.c
(51.17 KiB) Downloaded 275 times
SD Project.fcf_avr
(4 KiB) Downloaded 283 times

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 16 Not Working

Post by Benj »

Hello,

Thanks for posting the files.

Here is a updated component c file that should allow the compilation to work correctly.
Attachments
AVR_FAT16.c
(51.99 KiB) Downloaded 277 times

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

Thanks for posting the files.

Here is a updated component c file that should allow the compilation to work correctly.

That worked! I saw that there was some code in the component c code file that was for FAT32. Does that mean that this component is capable of connecting to a card formatted to FAT32?

Thank you very 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 16 Not Working

Post by Benj »

Hello,

Yes FAT32 should be supported in this C file.

To use it you need to find this line in the C file or use component customisation on the defines section and find the line.

Code: Select all

	#define MX_FAT_TYPE				0//%l		//0-FAT16(FAT) / 1-FAT32 / 2-FAT16&32
Change the number to suit the file system you require.

eg

Code: Select all

	#define MX_FAT_TYPE				2//%l		//0-FAT16(FAT) / 1-FAT32 / 2-FAT16&32
Will auto detect the file system on the card but will take up a bit more memory on the microcontroller.

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

Yes FAT32 should be supported in this C file.

To use it you need to find this line in the C file or use component customisation on the defines section and find the line.

Code: Select all

	#define MX_FAT_TYPE				0//%l		//0-FAT16(FAT) / 1-FAT32 / 2-FAT16&32
Change the number to suit the file system you require.

eg

Code: Select all

	#define MX_FAT_TYPE				2//%l		//0-FAT16(FAT) / 1-FAT32 / 2-FAT16&32
Will auto detect the file system on the card but will take up a bit more memory on the microcontroller.
Hello again,

I tried your new FAT16 component you gave me and it compiles just fine. But, for some reason when I run the Init_FAT it always returns a 255. Any idea what that means?

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 16 Not Working

Post by Benj »

Hello,

Here is a list of the error codes from the component help file.

Return Codes
0xFF - No Card Error
0xFE - No Response Error
0xFD - No Ack Error
0xFC - Timeout Error
0xFB - Reserved Error
0xFA - Bad Sector Error
0xEF - File Not Found Error
0xEE - Root Full Error
0xED - Sector Bytes Error
0x03 - File Empty
0x02 - File Type
0x01 - End Of File
0x00 - Ok

255 is 0xFF so no card detected.

Are you sure you have the hardware connected up correctly. Are you using E-blocks or your own hardware?

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

Here is a list of the error codes from the component help file.

Return Codes
0xFF - No Card Error
0xFE - No Response Error
0xFD - No Ack Error
0xFC - Timeout Error
0xFB - Reserved Error
0xFA - Bad Sector Error
0xEF - File Not Found Error
0xEE - Root Full Error
0xED - Sector Bytes Error
0x03 - File Empty
0x02 - File Type
0x01 - End Of File
0x00 - Ok

255 is 0xFF so no card detected.

Are you sure you have the hardware connected up correctly. Are you using E-blocks or your own hardware?
That's odd. I'm pretty sure the hardware is setup correctly. I tested the SD card setup with my arduino and it seems to recognize it. Yes, I am using my own hardware. I also tested another card, same problem--returns 255.

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

Re: FAT 16 Not Working

Post by JohnCrow »

Hi
Not sure if this will help but I had a problem with the card reader quite some time ago.
(The component has been updated since then though)
I found a Sandisk 2GB class 2 card worked fine but a Panasionic 2GB class 4 was not recognised. i.e retval gave 255
We eventually got it to work by changing a delay in the card reader component C code.

http://www.matrixmultimedia.com/mmforum ... ard#p23382

This was with PIC Flowcode.
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

Re: FAT 16 Not Working

Post by rocket200 »

JohnCrow wrote:Hi
Not sure if this will help but I had a problem with the card reader quite some time ago.
(The component has been updated since then though)
I found a Sandisk 2GB class 2 card worked fine but a Panasionic 2GB class 4 was not recognised. i.e retval gave 255
We eventually got it to work by changing a delay in the card reader component C code.

http://www.matrixmultimedia.com/mmforum ... ard#p23382

This was with PIC Flowcode.
I'm having trouble finding where to insert the delays. Could you tell me where you put yours? Thanks!

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

Re: FAT 16 Not Working

Post by rocket200 »

rocket200 wrote:
JohnCrow wrote:Hi
Not sure if this will help but I had a problem with the card reader quite some time ago.
(The component has been updated since then though)
I found a Sandisk 2GB class 2 card worked fine but a Panasionic 2GB class 4 was not recognised. i.e retval gave 255
We eventually got it to work by changing a delay in the card reader component C code.

http://www.matrixmultimedia.com/mmforum ... ard#p23382

This was with PIC Flowcode.
I'm having trouble finding where to insert the delays. Could you tell me where you put yours? Thanks!
Never mind, found it. Looks like it was already at 10us. So, the problem must be something else.

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 16 Not Working

Post by Benj »

Hello,

AVRs generally run a bit faster then PICs so it might be worth taking the delay up to 20 or 30 to see if that helps any. Also some older cards might run quite slowly anyway so worth a shot. Another option maybe to try a slower crystal as this will slow down the SPI hardware clock. Also worth a quick shot to see if it helps.

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

AVRs generally run a bit faster then PICs so it might be worth taking the delay up to 20 or 30 to see if that helps any. Also some older cards might run quite slowly anyway so worth a shot. Another option maybe to try a slower crystal as this will slow down the SPI hardware clock. Also worth a quick shot to see if it helps.

Tried changing the delay to 20, 30, 100, and 1000. Still returning 255.

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 16 Not Working

Post by Benj »

Hello,

Have you tried a slower crystal or switching to the software SPI impementation?

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

Re: FAT 16 Not Working

Post by rocket200 »

Benj wrote:Hello,

Have you tried a slower crystal or switching to the software SPI impementation?
Finally figured it out! It works!!! Here is what was causing it to not work; I was using the internal oscillator. I figured it would be fine running off the internal, but it turns out I needed to use a crystal. Once I hooked one up it worked like a charm!

Thanks for the help guys!

Post Reply