FAT32 library and SDHC cards
FAT32 library and SDHC cards
I am using the Mikrobasic Pro for PIC32 comiler with the FAT32 library. I am trying to write to an SD card. I am finding that if I use an old SD card I can get the FAT32_init to work but if I use any modern SDHC card the initilization fails. The libarary states that it is compatible with both SD and SDHC so I am confused as to why it wont work. I have tried an 8GB class 4 SDHC card and an 8GB class 10 card. I have tried using different speeds for initializing the SPI bus but nothing seems to work. Has anyone else had issues with SDHC cards and the FAT32 library?
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: FAT32 library and SDHC cards
Dear Baker,
We tested our libraries and examples with 8GB SDHC cards and everything was working.
Can you tell we which hardware are you using? Also exactly the name of the card which you are using?
Did you format your cards before you use them?
Best regards,
Aleksandar
We tested our libraries and examples with 8GB SDHC cards and everything was working.
Can you tell we which hardware are you using? Also exactly the name of the card which you are using?
Did you format your cards before you use them?
Best regards,
Aleksandar
Re: FAT32 library and SDHC cards
I am using the 1) Mikrobasic Pro for PIC32, 2)MikroProg USB programmer 3)PIC32MX130F064B chip at 40MHz. The SD cards are 1) Sandisk 256 MB Sd card (this is the one that works) 2) Sony SDHC class 10, 8GB card and 3)Sandisk class 4, 8GB card. All cards are formatted to FAT32 format. The relevant snippet of code that I am using for the MMC initialization is as follows:
'MMC/SD card variables
dim err as int8
dim fid as short
dim wrbuf as uint8[530]
bufferIndex as word
dim
filename as string[20] ' File name
character as byte
loop_, loop2 as byte
size as longint
' MMC module connections
dim MMC_chip_select as sbit at LATB10_bit ' for writing to output pin always use latch
dim MMC_chip_select_direction as sbit at TRISB10_bit
.
.
.
main:
TRISA=0
TRISB=0
trisb.4=0
TRISB.5=1 'MISO SD card
TRISB.12=0
TRISB.14=0
TRISB.15=0 'SDI is an input for the RF module (output for MCU)
TRISB.13=1 'SDO
' TRISB=0
AD1CON1.15=0 ' turn off ADC
ANSELB=0 'make portb pins digital
CM1CON.15=0 'turn off Comparator 1
CM2CON.15=0 'turn off Comparator 2
CM3CON.15=0 'turn off Comparator 3
JTAGEN_bit = 0 ' Disable JTAG
PMCON.15=0 'turn off parallel master port
RPB9R=0 'turn off pin remapping for pin RB9
RPB8R=0 'turn off pin remapping for pin RB8
RPB14R=0 'turn off pin remapping for pin RB14
SDI1R=%00000001 'map SDI to pin RB5
RPB11R=%0011 'map SDO to pin RB11
CTMUCON.15=0 'turn off Charge Time Measurement Unit
CVRCON.15=0 'turn off voltage reference
'=======================================================
'initialize SPI
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE)
Delay_ms(10)
'--------initiialize MMC Card--------
err = FAT32_Init()
while(err < 0) ' ...retry each 100 millisecond
err = FAT32_Init()
Delay_ms(100)
led_Green=not led_green
wend
'reinitialize SPI to higher speed
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 8, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE)
Delay_ms(10)
' open file
filename="TestFAT32lib"
fid = FAT32_Open(@filename, FILE_WRITE_F32)
'-------------End MMC card---------
'MMC/SD card variables
dim err as int8
dim fid as short
dim wrbuf as uint8[530]
bufferIndex as word
dim
filename as string[20] ' File name
character as byte
loop_, loop2 as byte
size as longint
' MMC module connections
dim MMC_chip_select as sbit at LATB10_bit ' for writing to output pin always use latch
dim MMC_chip_select_direction as sbit at TRISB10_bit
.
.
.
main:
TRISA=0
TRISB=0
trisb.4=0
TRISB.5=1 'MISO SD card
TRISB.12=0
TRISB.14=0
TRISB.15=0 'SDI is an input for the RF module (output for MCU)
TRISB.13=1 'SDO
' TRISB=0
AD1CON1.15=0 ' turn off ADC
ANSELB=0 'make portb pins digital
CM1CON.15=0 'turn off Comparator 1
CM2CON.15=0 'turn off Comparator 2
CM3CON.15=0 'turn off Comparator 3
JTAGEN_bit = 0 ' Disable JTAG
PMCON.15=0 'turn off parallel master port
RPB9R=0 'turn off pin remapping for pin RB9
RPB8R=0 'turn off pin remapping for pin RB8
RPB14R=0 'turn off pin remapping for pin RB14
SDI1R=%00000001 'map SDI to pin RB5
RPB11R=%0011 'map SDO to pin RB11
CTMUCON.15=0 'turn off Charge Time Measurement Unit
CVRCON.15=0 'turn off voltage reference
'=======================================================
'initialize SPI
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE)
Delay_ms(10)
'--------initiialize MMC Card--------
err = FAT32_Init()
while(err < 0) ' ...retry each 100 millisecond
err = FAT32_Init()
Delay_ms(100)
led_Green=not led_green
wend
'reinitialize SPI to higher speed
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 8, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE)
Delay_ms(10)
' open file
filename="TestFAT32lib"
fid = FAT32_Open(@filename, FILE_WRITE_F32)
'-------------End MMC card---------
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: FAT32 library and SDHC cards
Hi,
I suggest you to use some partition program and set format your cards with this settings:
Create As: Primary
File System: FAT32
Cluster Size: 512 (this should be default)
Partition Align To: Cylinder
Also, did you try to customize our example for FAT32?
Best regards,
Aleksandar
I suggest you to use some partition program and set format your cards with this settings:
Create As: Primary
File System: FAT32
Cluster Size: 512 (this should be default)
Partition Align To: Cylinder
Also, did you try to customize our example for FAT32?
Best regards,
Aleksandar
Re: FAT32 library and SDHC cards
OK, I will give these re-formatting options a try. I did not attempt to directly modify your example code. That's a good idea just to make sure I start from a good set of code.
Knowing that the newer SDHC cards are actually supported is a big help (I wasnt sure actually). Based on your replies it sounds like the problem is in my setup/code and not in the library.
I will reply back if I can get them to work. Thanks for the feedback.
Knowing that the newer SDHC cards are actually supported is a big help (I wasnt sure actually). Based on your replies it sounds like the problem is in my setup/code and not in the library.
I will reply back if I can get them to work. Thanks for the feedback.
Re: FAT32 library and SDHC cards
Hi Alexander,
So I have reformatted both the S4 and S10 cards and removed a stray connection in my breadboard (I think this is why the class 4 device did not work). The class 4 SDHC card now works fine but the class 10 card does not. It continues to fail at the initialization step. Could you please confirm that the library has indeed been checked with class 10 cards? Agaiin this is just so that I can be sure the problem is with my setup and not with an incompatibility. Thanks
So I have reformatted both the S4 and S10 cards and removed a stray connection in my breadboard (I think this is why the class 4 device did not work). The class 4 SDHC card now works fine but the class 10 card does not. It continues to fail at the initialization step. Could you please confirm that the library has indeed been checked with class 10 cards? Agaiin this is just so that I can be sure the problem is with my setup and not with an incompatibility. Thanks
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: FAT32 library and SDHC cards
Hi,
I checked, we tested our library with Class 4 cards. And we use them on mikromedia boards.
Unfortunately we didn't use Class 10 cards nor did we test them.
But there should not be any problem.
If you have some problem please check the speed of your SPI since the minimum writing speed for this cards should be 10 Mb/s or better.
Best regards,
Aleksandar
I checked, we tested our library with Class 4 cards. And we use them on mikromedia boards.
Unfortunately we didn't use Class 10 cards nor did we test them.
But there should not be any problem.
If you have some problem please check the speed of your SPI since the minimum writing speed for this cards should be 10 Mb/s or better.
Best regards,
Aleksandar
Re: FAT32 library and SDHC cards
OK, thanks for the reply.
-
- Posts: 17
- Joined: 03 Apr 2012 06:31
Re: FAT32 library and SDHC cards
Hi bakerj,
I have the same problem previously. In debug mode, the MMC can be initialized without problem for class 4 and class 10 but it failed in the FAT32 initialization. When I used the library from DANY (http://www.libstock.com/projects/view/58/fat), I found more cards could be recognized. I have tried ScanDisk class 4 and class 10 (from 8G, 16G and 32 G). The library worked. I don't know whether it will work for other cards from different brand. You can give it a try. I don't know the reason but I guess it is how the initialization routine in identifying the returned values from the card. The functions and the usage of this library are different from FAT32 and so you might need to rewrite the code.
In here, I would like to say thanks to Dany for creating many useful libraries that help me solve the problems.
I have the same problem previously. In debug mode, the MMC can be initialized without problem for class 4 and class 10 but it failed in the FAT32 initialization. When I used the library from DANY (http://www.libstock.com/projects/view/58/fat), I found more cards could be recognized. I have tried ScanDisk class 4 and class 10 (from 8G, 16G and 32 G). The library worked. I don't know whether it will work for other cards from different brand. You can give it a try. I don't know the reason but I guess it is how the initialization routine in identifying the returned values from the card. The functions and the usage of this library are different from FAT32 and so you might need to rewrite the code.
In here, I would like to say thanks to Dany for creating many useful libraries that help me solve the problems.
Re: FAT32 library and SDHC cards
Thanks for the information. I will give this library a try.
Re: FAT32 library and SDHC cards
I have the same problem with class 10 sd kart, but it works well with small classes.
I think Mikroe should fix this problem.
I think Mikroe should fix this problem.
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: FAT32 library and SDHC cards
Dear erpay,
Can you please tell me have you tried some other SD cards Class 10 from a different manufacturer?
We have tested our library with some SD cards Class 10 and its working.
Best regards,
Aleksandar
Can you please tell me have you tried some other SD cards Class 10 from a different manufacturer?
We have tested our library with some SD cards Class 10 and its working.
Best regards,
Aleksandar