FAT always gives 255 (no card?)

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

FAT always gives 255 (no card?)

Post by mikn »

i'm using aready built device based on pic24fj
it takes data from analogue input and saves onto sdcard. herein i mean, the hardware works well with original firmware.
i made a simple flowcode project just to initialise sdcard on this device but always receive code 255 as a result of fat::initialise.
i am 100% sure i connected cs,di,do and clk sdcard pins correctly. power is ok.
pic24 is set to 4mhz.
prescaler on fat component is set to 1/16 to meet <400khz requirement.

my project is here http://www.sendspace.com/file/kzj69l

what settings may be wrong?
FC 6.1.3.2 (18.02.2016)

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 always gives 255 (no card?)

Post by Jordy101091 »

Hi mikn,

First of all, when you want to upload a Flowcode file please attach this to you post instead of uploading this to a secondary site.
The reason why im saying this is because the site you uploaded to, gives me a crap load of ads.

Anyway, I had a look to you Flowcode file.
I must say I cannot find any mistakes or wrong settings, the only thing I did notice was the some what different way of initialising your FAT Component.
The first thing you do is initialise retval with a value of 1, this is good because you wont get false positive result.
the next thing you do is call the initialise function of the Fat component, if the card is not properly initialised then this component will return a non zero value, probably 255.
So what I would do is the following:

between the 2 delay blocks of 1sec. insert a while loop. the condition to leave this loop will be "Until Retval = 0" you could also do this "While Retval <> 0".
In this loop insert your Initialise function of your Fat Component and add a delay of 1sec.

in this setup you are continuously looking if the SD card in initialised properly, for instance if the program doesn't leave this loop after 5 initialise attempts then there is must be a problem with your hardware connections (just check this one more time), but because you say you are 100% sure that all the connections are correct, then there must be a problem with the FAT component.

In that case I cannot help you. you would have to contact Benj or other members from MM team to help you.

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

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

I'm sorry about uploading the file to sendspace, just couldn't find a button Attach file here in my post (maybe, because I have new account?)

I tried to put initialize into the loop with "until retval=0" but then it loops forever. Since the device doesn't have any lcd display, but only one led, i decided to use it to strobe the retval result after 1 second after initialize.
In original firmware sdcard initializes within 0.5 seconds and start working immediately, that's why I thought it must initialize same way, immediately.

Also I tried to exchange DI and DO pins, that didn't work anyway.
Also I tried to put DI and DO pins to some other pins (not really connected). Then the project freezes on the initialize function, so seems like DI and DO are set correctly at previous time.
I changed 5 different sdcards from 512mb to 2gb. Formatted them to fat16 with 512bytes blocks, but nothing helped.

Now I am confused about pic24 configure bits. Played with different choices but didn't succeed.

Any other advices what else to check?
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

seems like a problem may be around AD1PCFG, since PORTB in pic24 is analogue by default and need to be set to digital.
I've added C implementation:
AD1PCFG = 0xffff;

But it didn't work anyway. Do I need to declare it another way?
Also does the FAT component set port directions by itself or do I need to do this manually?
FC 6.1.3.2 (18.02.2016)

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 always gives 255 (no card?)

Post by Jordy101091 »

I think, don't quote me on this.

Flowcode handles the port directions for you, so as for as I know you don't have to do anything about this.
As I have said before, im not 100% sure about this, the best person to ask is one of the MM Team.

Regards Jordy
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 always gives 255 (no card?)

Post by Benj »

Hello,

Yes the I/O should be put into the right mode automatically as long as the pin connections are correct for your hardware.

Flowcode should also take care of any start up requirements to get the chip into digital I/O mode.

I'll have a go on a dsPIC target now just to sanity check and let you know how I get on.

Out of interest which version of V6 are you running? You can find out by going to Help -> About. The current released version is 6.0.4.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

Benj wrote: Out of interest which version of V6 are you running?
Yes, it's 6.0.4.0 (27.11.2013)
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

I don't know if this matters: the card is MICROsd, not SD actually. As i know they have identical interface, but maybe for the FAT component there are some differences?
FC 6.1.3.2 (18.02.2016)

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 always gives 255 (no card?)

Post by Jordy101091 »

There is no difference in interfacing a SD or MicroSD card, the only differences are the dimensions of the card.
So to answer your question, If everything is working you should be able to interface microSD aswel as a standard SD Card.

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

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

Then I am out of idea what may be wrong. I can share the layout file if it will help to resolve the issue. It's not for public but I can send to PM
FC 6.1.3.2 (18.02.2016)

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 always gives 255 (no card?)

Post by Jordy101091 »

If you want I can have look at your layout file.
You can send this to me via PM.

Regards Jordy
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 always gives 255 (no card?)

Post by Benj »

Hello,

The FAT component should work with SD and MicroSD but be careful as the Micro SD pin out is not the same as the standard SD card. I've made this mistake before!
sd-card-pinout.png
(58.5 KiB) Downloaded 3705 times

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT always gives 255 (no card?)

Post by Mathy »

I confirm that I used Flowcode 5 with microSD card with success. Not yet with the V6.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

I've got some success! Hooray! I have another variant of same device with another PCB, but same pic24 and another ports connected to microsd. It had same problem but after I exchanged DO and DI pins it worked well, card initialized and i could create text file.
All settings are the same. The difference is in pinout
first model, which i can't connect:
CS=RB15, DI=RB9, DO=RB14, CLK=RB13
second model, which i could connect:
CS=RB15, DI=RB6, DO=RB14, CLK=RB7

Seems like something is wrong with portB 9th and 13th pins, isn't it?
According to datasheet of my chip these ports have other functions. Maybe some of them must be switched off? Seems like they are off as I see in config.
Image
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT always gives 255 (no card?)

Post by mikn »

So, no idea why it doesn't work on RB9 and 13 in first case and works on RB6 and 7 in second case?
According to Benj's words, FAT must setup those pins automatically, but seems like something is wrong.

ps: with original firmware both devices work ok, so I am 200% sure that hardware connection is correct.
FC 6.1.3.2 (18.02.2016)

Post Reply