v5 Beta FAT16 component SDHC
Moderator: Benj
- 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:
v5 Beta FAT16 component SDHC
Hello Nicolas,
I haven't had time to test this on hardware yet but it compiles now so hopefully it should work. I need to buy in some SDHC cards to do the testing so may take a few days. In the meantime if you want to give it a go then backup the FC5_PIC_FAT16.c file in the "Flowcode xxx\v5\Components" folder and then copy in the attached file before starting Flowcode.
Let me know how you get on.
I haven't had time to test this on hardware yet but it compiles now so hopefully it should work. I need to buy in some SDHC cards to do the testing so may take a few days. In the meantime if you want to give it a go then backup the FC5_PIC_FAT16.c file in the "Flowcode xxx\v5\Components" folder and then copy in the attached file before starting Flowcode.
Let me know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- JohnCrow
- Valued Contributor
- Posts: 1367
- Joined: Wed Sep 19, 2007 1:21 pm
- Location: Lincolnshire
- Has thanked: 364 times
- Been thanked: 716 times
Re: SD Card not response
Hi Benj
Does this mean the new component will work with cards bigger than 2GB ?
Also will It work formatted FAT16 or does it need to be FAT32.
I'll give it a try tonight if I get chance with an 8GB card.
Does this mean the new component will work with cards bigger than 2GB ?
Also will It work formatted FAT16 or does it need to be FAT32.
I'll give it a try tonight if I get chance with an 8GB card.
1 in 10 people understand binary, the other one doesn't !
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: SD Card not response
Hi Ben,
I ve renamed FC5_PIC_FAT16.c in FC5_ARM_FAT16.c and replaced in Components Folder.
Unfortunately, component not working with all SDCard.
- With SDCard no SDHC < 2GO, After Init FAT macro I have Retval = Dec 237 (0xED hex code error -> SECTBYTES ERROR)
(Ok with old FAT component version)
- With SDCard SDHC 4GO 15MB/s (Class 4), After Init FAT macro I have Retval = Dec 254 (0xFE hex code error -> NORESP ERROR)
I ve tried in FAT32 select and AUTO select but with the even problem.
Thank for your reply,
Regards,
Nicolas.
I ve renamed FC5_PIC_FAT16.c in FC5_ARM_FAT16.c and replaced in Components Folder.
Unfortunately, component not working with all SDCard.
- With SDCard no SDHC < 2GO, After Init FAT macro I have Retval = Dec 237 (0xED hex code error -> SECTBYTES ERROR)
(Ok with old FAT component version)
- With SDCard SDHC 4GO 15MB/s (Class 4), After Init FAT macro I have Retval = Dec 254 (0xFE hex code error -> NORESP ERROR)
I ve tried in FAT32 select and AUTO select but with the even problem.
Thank for your reply,
Regards,
Nicolas.
- 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: SD Card not response
Hi Nicolas & John,
Ok thanks for testing and providing the results so quickly. A bit disappointed it didn't work but not giving up just yet. I will have another dig in tonight and see if I can get any further.
I was using the Microchip SD stack as a template as this works nicely on a range of cards however it is really overcomplicated and bloated and it's not until you start to try and port it that you realise just how bad it is. Code replicated in multiple places, definitions that are bypassed or not used in the code and lots of weird compiler workarounds that would likely just cause issues with BoostC and GCC. Last night I found an AVR GCC source which is really simple and fits in with the current code base. It is said to work but obviously I have done something wrong if this is not currently working with your hardware.
The sector bytes error is interesting and may help me to debug the issue.
Ok thanks for testing and providing the results so quickly. A bit disappointed it didn't work but not giving up just yet. I will have another dig in tonight and see if I can get any further.
I was using the Microchip SD stack as a template as this works nicely on a range of cards however it is really overcomplicated and bloated and it's not until you start to try and port it that you realise just how bad it is. Code replicated in multiple places, definitions that are bypassed or not used in the code and lots of weird compiler workarounds that would likely just cause issues with BoostC and GCC. Last night I found an AVR GCC source which is really simple and fits in with the current code base. It is said to work but obviously I have done something wrong if this is not currently working with your hardware.
The sector bytes error is interesting and may help me to debug the issue.
Yes eventually I hope to be able to support larger cards and I also want to make the SPI transactions post init much faster. One use for this may be with the DSP type functionality we are doing to provide high quality streaming audio etc.Does this mean the new component will work with cards bigger than 2GB ?
I think FAT16 only supports cards <= 2GB so FAT32 may have to be used on larger cards, not 100% on this one. Do you get FAT as an option when you format a card larger then 2GB?Also will It work formatted FAT16 or does it need to be FAT32.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: SD Card not response
Ok Ben,
For information:
My Small SDCard is Transcend 2GO formated in FAT32, OK with old FAT component version (but with speed writting problem when data on card is > 100 MO).
My SDHC Card is SanDisk 4GO 15MB/s Class 4 formated in FAT32 -> NORESP ERR
Good Job for tonight, I hope it will work
Nicolas.
For information:
My Small SDCard is Transcend 2GO formated in FAT32, OK with old FAT component version (but with speed writting problem when data on card is > 100 MO).
My SDHC Card is SanDisk 4GO 15MB/s Class 4 formated in FAT32 -> NORESP ERR
Good Job for tonight, I hope it will work

Nicolas.
- 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: SD Card not response
Just noticed that all the SDHC cards seem to say FAT32 which I guess is understandable as a FAT16 file system would need huge cluster sizes and therefore would have large levels of redundant sectors if you had lots of small files on the card.I think FAT16 only supports cards <= 2GB so FAT32 may have to be used on larger cards, not 100% on this one. Do you get FAT as an option when you format a card larger then 2GB?
The quest for SDHC continues....
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: SD Card not response
The SECTBYTES ERROR is related to whether the start of the partition is found. I have not edited this code so I wonder why this is failing to work correctly?
Hm, the plot thickens.
Hm, the plot thickens.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: SD Card not response
Right I have found a couple of bugs that meant that the sector read and write functions were not working correctly which probably explains the SECTBYTE error. I think this has now been fixed and I've again checked it compiles. I'm hoping this will at the very least allow the originally working card to fire up again. I have a v5 working card here so I will give this a go tonight if I get time.
Not sure what the issue is with the SDHC as this code looked ok, definitely worth retesting to see if it gets any further. In the example code it calls the init function 20 times in a loop checking for a return value of 0 before giving up.
Not sure what the issue is with the SDHC as this code looked ok, definitely worth retesting to see if it gets any further. In the example code it calls the init function 20 times in a loop checking for a return value of 0 before giving up.
- Attachments
-
- FC5_PIC_FAT16.c
- (54.73 KiB) Downloaded 472 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: v5 Beta FAT16 component SDHC
No go here
Still working on it. Maybe tomorrow!
The card init is working ok but when getting to the part where it should be reading the MBR I am just getting 0's. Hopefully should be simple to fix.
Nicolas' card is firing up correctly so it looks like the issue is just with my card, still no go on the SDHC type cards yet though.


The card init is working ok but when getting to the part where it should be reading the MBR I am just getting 0's. Hopefully should be simple to fix.
Nicolas' card is firing up correctly so it looks like the issue is just with my card, still no go on the SDHC type cards yet though.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
Hello Ben,
(mp copy)
Better but other problem:
With SDCard No SDHC 2GO FAT32, Init FAT OK
Next step -> Scan_Current_Folder OK But name of folder is no good, "TRON" becomes "puovpvpwpxq"
Result -> Open Folder Error
With SDHC SDCard Error 254 on Init FAT
My prog is a loop of Init_Fat if Retval > 0 with a small delay after Init_Fat.
(.fcm export in mp)
- I ve tested in Software mode, exactly even problem.
- I ve tested with "mx_sdhc_flag = 1" fixed in macro, but Retval = 254 with SDHC Card.
Regards,
Nicolas
(mp copy)
Better but other problem:
With SDCard No SDHC 2GO FAT32, Init FAT OK
Next step -> Scan_Current_Folder OK But name of folder is no good, "TRON" becomes "puovpvpwpxq"
Result -> Open Folder Error
With SDHC SDCard Error 254 on Init FAT
My prog is a loop of Init_Fat if Retval > 0 with a small delay after Init_Fat.
(.fcm export in mp)
- I ve tested in Software mode, exactly even problem.
- I ve tested with "mx_sdhc_flag = 1" fixed in macro, but Retval = 254 with SDHC Card.
Regards,
Nicolas
- 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: v5 Beta FAT16 component SDHC
Cheers Nicolas,
Right I'm back on with it now so I will let you know how I get on. Hopefully I can fix the file system related errors.
As for the SDHC, still not managed to get hold of one for testing yet so I am continuing with this standard class 1 SD that did not work previously, hopefully I can get somewhere with this. Annoying thing is it works great with the Microchip stack and so can work via the SPI interface!
If my SDHC card hasn't arrived tomorrow then I will nip down to the supermarket so I have one for the weekend.
This will not beat me
(famous last words)
Right I'm back on with it now so I will let you know how I get on. Hopefully I can fix the file system related errors.
As for the SDHC, still not managed to get hold of one for testing yet so I am continuing with this standard class 1 SD that did not work previously, hopefully I can get somewhere with this. Annoying thing is it works great with the Microchip stack and so can work via the SPI interface!
If my SDHC card hasn't arrived tomorrow then I will nip down to the supermarket so I have one for the weekend.
This will not beat me

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: v5 Beta FAT16 component SDHC
Hello,
Right I think I have a stable version now. At least it's working with the two standard SD cards I have, 1 which worked with the original v5 code and 1 which didn't.
Next step is getting the SDHC card working, if it's not already
I have also implemented a speed increase in the component code, if the init function fails then the code will try and dial back the speed for initialisation but then push it back up for the data transfer. Seems to be working well and confirmed running faster then the original v5 code on an ECIO PIC
Let me know how you get on with the new ARM CAL file, I have tested in software mode and it appears to be working.
- Edit - Confirmed AVR also working in SW mode
Right I think I have a stable version now. At least it's working with the two standard SD cards I have, 1 which worked with the original v5 code and 1 which didn't.
Next step is getting the SDHC card working, if it's not already

I have also implemented a speed increase in the component code, if the init function fails then the code will try and dial back the speed for initialisation but then push it back up for the data transfer. Seems to be working well and confirmed running faster then the original v5 code on an ECIO PIC

Let me know how you get on with the new ARM CAL file, I have tested in software mode and it appears to be working.
- Edit - Confirmed AVR also working in SW mode
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
Ok Ben,
I have Retval = 237 with this Mx_Init_Card.
If I replace Mx_Init_Card by this Mx_Init_Card it's OK with 2GO SDCard and new CAL, FAT, files.
I have Retval = 237 with this Mx_Init_Card.
If I replace Mx_Init_Card by this Mx_Init_Card it's OK with 2GO SDCard and new CAL, FAT, files.
and MX_SPI_BYTEMX_UINT8 RetVal;
MX_SINT16 i;
delay_ms(50); //Wait for card to power up
//Init SPI
%a_SPI_Master_Init(); //Call initialise function
FC_CAL_Bit_High_DDR (%a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_TRIS, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is disabled
for(i = 0; i < 10; i++) //Start CARD in SPI mode
{
%a_SPI_Master_Byte(0xFF); //Send 10*8=80 clock pulses
}
FC_CAL_Bit_Low ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is enabled
delay_us(50); //Wait 50us
//Command 0 - Goto Idle State - Resets card
RetVal = MX_Send_Cmd(0,0);
FC_CAL_Bit_High ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is disabled
if (RetVal != 1)
return MX_ERR_NOCARD; //Card not initialising or not present
delay_us(50); //Wait 50us
FC_CAL_Bit_Low ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is enabled
//Command 1 - Send Operating Condition - Reports the status of the card
i = 10000;
do
{
RetVal = MX_Send_Cmd(1,0);
FC_CAL_Bit_High ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); //CARD-Disabled
}
while ((RetVal) && (i--)); //Loop while processing command 1
if (RetVal)
return MX_ERR_NORESP; //Card not responding
//Need a good way of applying this speed update!!!
//%a_SPI_Master_Uninit(); //Disable Low Speed
//%a_FAT.AsByteus_mode = 1; //SPI Bus Mode //Check this value
//%a_SPI_Master_Init (); //Enable Hi Speed
//Hardware Mode only
AT91F_SPI_CfgCs(AT91C_BASE_SPI, 0, (12 << FCV_SPI_SPEED) | AT91C_SPI_NCPHA | AT91C_SPI_CPOL); // 8MBaud @ 48MHz MCK
return MX_ACK_OK; //Card Ready
MX_UINT8 RetVal;
MX_SINT16 i;
delay_ms(50); //Wait for card to power up
//Init SPI
%a_SPI_Master_Init(); //Call initialise function
FC_CAL_Bit_High_DDR (%a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_TRIS, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is disabled
for(i = 0; i < 10; i++) //Start CARD in SPI mode
{
%a_SPI_Master_Byte(0xFF); //Send 10*8=80 clock pulses
}
FC_CAL_Bit_Low ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is enabled
delay_us(50); //Wait 50us
//Command 0 - Goto Idle State - Resets card
RetVal = MX_Send_Cmd(0,0);
FC_CAL_Bit_High ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is disabled
if (RetVal != 1)
return MX_ERR_NOCARD; //Card not initialising or not present
delay_us(50); //Wait 50us
FC_CAL_Bit_Low ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); // Chip Select pin is enabled
//Command 1 - Send Operating Condition - Reports the status of the card
i = 10000;
do
{
RetVal = MX_Send_Cmd(1,0);
FC_CAL_Bit_High ( %a_MX_SPI_FAT_CS_PORT, %a_MX_SPI_FAT_CS_PIN); //CARD-Disabled
}
while ((RetVal) && (i--)); //Loop while processing command 1
if (RetVal)
return MX_ERR_NORESP; //Card not responding
//Need a good way of applying this speed update!!!
//%a_SPI_Master_Uninit(); //Disable Low Speed
//%a_FAT.AsByteus_mode = 1; //SPI Bus Mode //Check this value
//%a_SPI_Master_Init (); //Enable Hi Speed
//Hardware Mode only
AT91F_SPI_CfgCs(AT91C_BASE_SPI, 0, (12 << FCV_SPI_SPEED) | AT91C_SPI_NCPHA | AT91C_SPI_CPOL); // 8MBaud @ 48MHz MCK
return MX_ACK_OK; //Card Ready
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
I've tried with FC5_PIC_FAT16.c version2 and new CAL file:
The better result, Without change code in component Macro Init Card is OK, but with this problem of bad folder name ...
FC5_PIC_FAT16.c version2
The better result, Without change code in component Macro Init Card is OK, but with this problem of bad folder name ...
FC5_PIC_FAT16.c version2
Benj wrote:Right I have found a couple of bugs that meant that the sector read and write functions were not working correctly which probably explains the SECTBYTE error. I think this has now been fixed and I've again checked it compiles. I'm hoping this will at the very least allow the originally working card to fire up again. I have a v5 working card here so I will give this a go tonight if I get time.Not sure what the issue is with the SDHC as this code looked ok, definitely worth retesting to see if it gets any further. In the example code it calls the init function 20 times in a loop checking for a return value of 0 before giving up.
Attachments
FC5_PIC_FAT16.c
(56.67 KiB) Downloaded 9 times
- 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: v5 Beta FAT16 component SDHC
Right I'm posting from my mobile due to lack on met at home. Just bought two sdhc cards and they are both working correctly with the current posted code
I will try and increase the reliability but looking good at this end.

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: v5 Beta FAT16 component SDHC
Using the current code I have 6 working cards 2 of which are sdhc 1 2GB and 1 4GB. The only card I have which isn't working is a mmc type card. May have got the prescaler values wrong for the arm so I will repeat the tests on this 

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
Very good news
Thank Ben for your working,
My hardware is like this dev card:
https://www.olimex.com/dev/pdf/SAM7S-P64.pdf
I use SPI hardware.
For test, I can take Olimex dev card.
With Flowcode, in macro component, I have Mx_macro duplicate, may be problem with new component file .c
I search this WE why my SDCard answer 237, and SDHC 254 ...
Good luck Ben.

Thank Ben for your working,
My hardware is like this dev card:
https://www.olimex.com/dev/pdf/SAM7S-P64.pdf
I use SPI hardware.
For test, I can take Olimex dev card.
With Flowcode, in macro component, I have Mx_macro duplicate, may be problem with new component file .c
I search this WE why my SDCard answer 237, and SDHC 254 ...
Good luck Ben.
Last edited by Nico595 on Sun Jul 22, 2012 11:27 am, edited 3 times in total.
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
Ok
,
I've imagined a problem with MBR reading in init FAT, I've placed your lower speed SPI mode in Init_FAT macro and SDCard 2GO is OK with your latest FAT component code in SPI hardware.
and I've replaced Prescaler number in Mx_Init_Card
Can you tell me if it's ok ?
SPI_Set_Prescaler() is very a good idea
For SDHC I have 254 return.
EDIT:
After more test with 2GO SDCard, reading OK, problem with writting -> Macro Create_File, no file created on SDCard or file without name.

I've imagined a problem with MBR reading in init FAT, I've placed your lower speed SPI mode in Init_FAT macro and SDCard 2GO is OK with your latest FAT component code in SPI hardware.
->delay_ms(50);
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
//if (retval)
//{
// %a_SPI_Set_Prescaler(4); //Try again
//retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
return MX_ERR_SECTBYTES;
//}
Finally I test Prescaler value for Init and Read MBR for best SPI speed value:delay_ms(50);
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(4); //Try again at a lower speed
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
return MX_ERR_SECTBYTES;
}
retval = MX_Init_Card(); //Startup Card
if (retval)
{
%a_SPI_Set_Prescaler(1); //Try again
retval = MX_Init_Card(); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(2); //Try again at a lower speed
retval = MX_Init_Card(); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(4); //Try again at a lower speed
retval = MX_Init_Card(); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(64); //Try again at a lower speed
retval = MX_Init_Card(); //Read Master Boot Record if available
if (retval)
return(retval); //Startup error or no card
}
}
}
}
delay_ms(50);
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(1); //Try again
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(2); //Try again at a lower speed
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(4); //Try again at a lower speed
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
{
%a_SPI_Set_Prescaler(64); //Try again at a lower speed
retval = MX_Get_Buffer(0); //Read Master Boot Record if available
if (retval)
return MX_ERR_SECTBYTES;
}
}
}
}
and I've replaced Prescaler number in Mx_Init_Card
Finally after Init, Prescaler value high for best SPI speed value://%a_SPI_Master_Uninit(); //Disable Low Speed
//%a_FAT.AsByteus_mode = 1; //SPI Bus Mode //Check this value
//%a_SPI_Master_Init (); //Enable Hi Speed
%a_SPI_Set_Prescaler(2);
return MX_ACK_OK; //Card Ready
//%a_SPI_Master_Init (); //Enable Hi Speed
%a_SPI_Set_Prescaler(1);
return MX_ACK_OK; //Card Ready
Can you tell me if it's ok ?
SPI_Set_Prescaler() is very a good idea

For SDHC I have 254 return.
EDIT:
After more test with 2GO SDCard, reading OK, problem with writting -> Macro Create_File, no file created on SDCard or file without name.
Last edited by Nico595 on Sun Jul 22, 2012 12:08 pm, edited 12 times in total.
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
With SDHC Card (test with two SDHC Card) I have NORESP ERROR.
Problem with Mx_Init_Card ACMD command ...
In Defines of FAT Component I add code error:
In Mx_Init_Card
After this Cmd I've created FCV for return value of RetVal
EDIT 22.07.2012:
OUFFFFFF, in French
SDHC Init OK,
My power of SDCard is a PA7, no good with SDHC
, after powered SDCard with 3.3v supply, SDHC Card Init OK

Perfect, Thank you very much Ben
Always problem with the Create_File macro, file is created but without name, result, bug SDCard reading.
Problem with Mx_Init_Card ACMD command ...
In Defines of FAT Component I add code error:
//Common Defines
#define MX_ERR_NOCARD 0xFF
#define MX_ERR_NORESP 0xFE
#define MX_ERR_SDHCNORESP 0x33
In Mx_Init_Card
I have error code 51 Dec -> 0x33 -> MX_ERR_SDHCNORESP -> time out, card initialization faileddo
{
RetVal = MX_Send_Cmd(APP_CMD, 0x00000000); //CMD55, must be sent before sending any ACMD command
RetVal = MX_Send_Cmd(SD_SEND_OP_COND, 0x40000000); //ACMD41
i++;
if(i>0xfe)
{
return MX_ERR_SDHCNORESP; //time out, card initialization failed
}
After this Cmd I've created FCV for return value of RetVal
RetVal = 1 Dec for %a_SPI_Set_Prescaler(); >= 1, But RetVal return must be 0 Dec (0x00)RetVal = MX_Send_Cmd(SD_SEND_OP_COND, 0x40000000); //ACMD41
EDIT 22.07.2012:
OUFFFFFF, in French

My power of SDCard is a PA7, no good with SDHC




Perfect, Thank you very much Ben

Always problem with the Create_File macro, file is created but without name, result, bug SDCard reading.
- 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: v5 Beta FAT16 component SDHC
Hi Nico,
Sorry I dug out all my ARM hardware on the weekend and then realised I didn't have v5 for ARM installed at home and as my net was down (and still is!) I couldn't download a copy. I will install tonight and specifically test the create file and write functions. Thanks for helping with the testing.
Sorry I dug out all my ARM hardware on the weekend and then realised I didn't have v5 for ARM installed at home and as my net was down (and still is!) I couldn't download a copy. I will install tonight and specifically test the create file and write functions. Thanks for helping with the testing.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Nico595
- Posts: 84
- Joined: Mon Jan 23, 2012 6:46 pm
- Location: France
- Has thanked: 12 times
- Been thanked: 10 times
Re: v5 Beta FAT16 component SDHC
Hi Ben,
No excuse, Weekend is for relaxation and no working
My card was powered with PA7 for reset, I have a problem, when I've readed card, I can't doing a new init_Fat, Card is no found. I must reset ARM for restart the reading card. I search later ...
I'm very happy FAT16 is OK with SDHC Card. I will test with others Card, faster.
For Create_File macro I think file is created without name but you must tested with your prog and hardware.
Good job Ben, Thanks
PS: If you want, you can delete my no necessary old post
No excuse, Weekend is for relaxation and no working

My card was powered with PA7 for reset, I have a problem, when I've readed card, I can't doing a new init_Fat, Card is no found. I must reset ARM for restart the reading card. I search later ...
I'm very happy FAT16 is OK with SDHC Card. I will test with others Card, faster.
For Create_File macro I think file is created without name but you must tested with your prog and hardware.
Good job Ben, Thanks

PS: If you want, you can delete my no necessary old post
