SDFileSystem.bas ???
Moderators: David Barker, Jerry Messina
Dear ohararp and Steven,
I am having difficulty in adapting it to my PIC18F2525. I need to put voltage dividers in between the pins from PIC to SD. So the arrangement became a bit complicated and confusing for me. How do you think I may add the pull ups into the wavplayer schematic? Can you put any suggestions to make it possible, maybe a rough schematic? (I dont have any 3.3V PIC).
Any help will do.
Thanks
Regards,
Liak
I am having difficulty in adapting it to my PIC18F2525. I need to put voltage dividers in between the pins from PIC to SD. So the arrangement became a bit complicated and confusing for me. How do you think I may add the pull ups into the wavplayer schematic? Can you put any suggestions to make it possible, maybe a rough schematic? (I dont have any 3.3V PIC).
Any help will do.
Thanks
Regards,
Liak
SD card schematic
Hi Liak, there is a schematic of a SD card daughter board on the Micro Electronika site that shows a switchable arrangement for the inputs to the SD card. (the voltage dividers can be switched in when used with a 5.0 V processor) you can find it at: http://www.mikroe.com/pdf/mmc_proto_schematic_v100.pdf
Does anyone know how critical it is to use the voltage dividers when using a 5.0 V processor? I'm working with a board designed around a 5 volt 18f8722 and the designer does not use dividers on the inputs to the SD card - all lines are pulled high with 10K. So far I'm not having any luck talking to the SD card. Is there a chance that the 3.3v electronics in the card plug could be damaged with such an arrangement?
Bryan
Does anyone know how critical it is to use the voltage dividers when using a 5.0 V processor? I'm working with a board designed around a 5 volt 18f8722 and the designer does not use dividers on the inputs to the SD card - all lines are pulled high with 10K. So far I'm not having any luck talking to the SD card. Is there a chance that the 3.3v electronics in the card plug could be damaged with such an arrangement?
Bryan
Dear all,
Thanks Bryan and ohararp. I am still working on the SD. Dead line running near and it's still not working. The card fails to init. Not sure why. It was running well before then, after it failed, it failed until now. And Steven, may I know why the adaptation for SDHC makes the module prone to failure when the pins are not pulled up? Can I get the version without the SDHC adaptation? All the schematics I see on the net does not include pull ups.
Liak
Thanks Bryan and ohararp. I am still working on the SD. Dead line running near and it's still not working. The card fails to init. Not sure why. It was running well before then, after it failed, it failed until now. And Steven, may I know why the adaptation for SDHC makes the module prone to failure when the pins are not pulled up? Can I get the version without the SDHC adaptation? All the schematics I see on the net does not include pull ups.
Liak
Interfacing 3.3v SD card to 5v PIC
Hi Liak, congratulations on your success! Did you end up using the voltage dividers?
I just came across what looks to me like fairly authoritive article on the interfacing of a SD card to a 5 volt PIC processor. Interesting what they say about the DO line from the SD card needing a TTL buffer. This is the first time I've seen anything indicating that!
article from this Link:
http://brushelectronics.com/index.php?page=software
Bryan
How to implement an SD/MMC Card with a PIC Microcontroller
A number of hardware reference designs incorporating SD/MMC Cards are available on our Projects page.
For a 3.3volt PIC system, the minimum interface between an SD/MMC card and the PIC is four I/O lines which include the three SPI bus lines (SCK, SDO and SDI) the fourth line is the chip select. Optionally two additional lines connect to the SD/MMC socket for Card Detect (CD) and Write Protect (WP).
For 5 volt PICs, level translation is required between the 5 volt I/O of the PIC and the 3.3 volt I/O of the SD/MMC Card. Level translation for the PIC SDO, SCK and CS outputs can be implemented with simple resistor voltage dividers.
***Coming from DO of the SD/MMC Card to the SDI input of the PIC is not so straight forward and requires a TTL buffer. This is because the PIC, in SPI mode, has the SDI input configured as a Schmidt trigger input and the guaranteed logic high out of the SD/MMC card is less than the guaranteed logic high level of the PIC. ***
When selecting a PIC for applications that write to a media card there are two main criteria; there is sufficient RAM to support the access method and the PIC supports an SPI bus. SD/MMC Cards must be written in 512 byte blocks. This is also the sector size of the SD/MMC card. So for example, to append a byte to a file, the sector must be read into a buffer, the location modified, and the sector written back to disk. If using a file system, a sector buffer is required for file system management and one 512 byte buffer plus local file variables are required for each open file. This means a PIC with 1500 bytes of memory, such as the PIC18F452, using a file system can realistically have only a single file open at a time. The PIC18F4620, which is pin compatible with the PIC18F452 has 3900 bytes of ram available and therefore can have multiple files open simultaneously.
I just came across what looks to me like fairly authoritive article on the interfacing of a SD card to a 5 volt PIC processor. Interesting what they say about the DO line from the SD card needing a TTL buffer. This is the first time I've seen anything indicating that!
article from this Link:
http://brushelectronics.com/index.php?page=software
Bryan
How to implement an SD/MMC Card with a PIC Microcontroller
A number of hardware reference designs incorporating SD/MMC Cards are available on our Projects page.
For a 3.3volt PIC system, the minimum interface between an SD/MMC card and the PIC is four I/O lines which include the three SPI bus lines (SCK, SDO and SDI) the fourth line is the chip select. Optionally two additional lines connect to the SD/MMC socket for Card Detect (CD) and Write Protect (WP).
For 5 volt PICs, level translation is required between the 5 volt I/O of the PIC and the 3.3 volt I/O of the SD/MMC Card. Level translation for the PIC SDO, SCK and CS outputs can be implemented with simple resistor voltage dividers.
***Coming from DO of the SD/MMC Card to the SDI input of the PIC is not so straight forward and requires a TTL buffer. This is because the PIC, in SPI mode, has the SDI input configured as a Schmidt trigger input and the guaranteed logic high out of the SD/MMC card is less than the guaranteed logic high level of the PIC. ***
When selecting a PIC for applications that write to a media card there are two main criteria; there is sufficient RAM to support the access method and the PIC supports an SPI bus. SD/MMC Cards must be written in 512 byte blocks. This is also the sector size of the SD/MMC card. So for example, to append a byte to a file, the sector must be read into a buffer, the location modified, and the sector written back to disk. If using a file system, a sector buffer is required for file system management and one 512 byte buffer plus local file variables are required for each open file. This means a PIC with 1500 bytes of memory, such as the PIC18F452, using a file system can realistically have only a single file open at a time. The PIC18F4620, which is pin compatible with the PIC18F452 has 3900 bytes of ram available and therefore can have multiple files open simultaneously.
Dear Bryan,
Thanks for sharing. I use voltage dividers. Seems to me the article is right. It was a nightmare struggling to init the SD card. I only found out by myself after testing it for 2 weeks!
I suspect the SD card failed to initialize because the SDO line is below TTL. I added pull up on the SDO line like Steven suggested. But the SDI (from PIC to SD) is left without and it works.
Regards,
Liak
Thanks for sharing. I use voltage dividers. Seems to me the article is right. It was a nightmare struggling to init the SD card. I only found out by myself after testing it for 2 weeks!
I suspect the SD card failed to initialize because the SDO line is below TTL. I added pull up on the SDO line like Steven suggested. But the SDI (from PIC to SD) is left without and it works.
Regards,
Liak
-
- Registered User
- Posts: 26
- Joined: Sun Oct 12, 2008 11:21 pm
- Location: Utah
Just starting to play with SD memory. I am using microSD cards. Trying the basic read write program that is in the sample directory.
The init seems to run in a loop, like the processor is restarting the program over and over.
I tried adding 10K pull ups on the SDO and SDI lines and still am stuck in the init loop.
What size pull ups did you use? I am using an 18f24J10, a 3.3v part.
I noticed on one of the other posts schematic that 2.2K pullups are used on all three SPI lines when 3.3v chips are used and 3.3K with 5v chips.
may try 2.2K on all three line spi lines tomorow.
any thoughts
RD
The init seems to run in a loop, like the processor is restarting the program over and over.
I tried adding 10K pull ups on the SDO and SDI lines and still am stuck in the init loop.
What size pull ups did you use? I am using an 18f24J10, a 3.3v part.
I noticed on one of the other posts schematic that 2.2K pullups are used on all three SPI lines when 3.3v chips are used and 3.3K with 5v chips.
may try 2.2K on all three line spi lines tomorow.
any thoughts
RD
Hello and welcome to the forum. Could you let me know if you are using the original version of the SD module that ships with the compiler, or the later version from the wiki (http://www.sfcompiler.co.uk/wiki/pmwiki ... temVersion). Could you also post the code you are using.
Thanks,
Steve
Thanks,
Steve
-
- Registered User
- Posts: 26
- Joined: Sun Oct 12, 2008 11:21 pm
- Location: Utah
I received the compiler a week ago. Have been using the version on the disk. After reading some of your previous posts I clicked the "online update". Still having the same problem. Are the "online update" files the same as on wiki? Have not changed the pullups to 2.2K or added the pullup on the CS line yet.
The only code I changed was to ad the Config settings. I found I had to change the default setting of using the internal 32Khz ocilator to get the chip to run at 20MHZ.
Code:
// device and clock...
Device = 18F24J10
Clock = 20
Config
DEBUG = OFF,
XINST = OFF,
STVREN = ON,
WDTEN = ON,
FCMEN = ON,
IESO = OFF,
FOSC2 = ON,
FOSC = HS,
WDTPS = 128
// import SD file system, usart and conversion modules...
#option SD_SPI = MSSP // use hardware SPI
Include "SDFileSystem.bas"
Include "usart.bas"
Include "Convert.bas"
// variables...
Dim Index As Byte
// program start...
SetBaudrate(br19200)
USART.Write("Initialising card...", 13, 10)
If SD.Init(spiOscDiv64) Then
// format SD card...
USART.Write("Formatting, please wait...", 13, 10)
QuickFormat
// write data to SD card...
USART.Write("Writing data, please wait...", 13, 10)
If SD.NewFile("test.txt") = errOK Then
For Index = 0 To 255
SD.Write("Line ",DecToStr(Index,3), 13, 10)
Next
SD.CloseFile
EndIf
// read data back...
USART.Write("Reading data...", 13, 10)
If SD.OpenFile("test.txt") = errOK Then
Repeat
USART.Write(SD.ReadByte())
Until SD.EOF
SD.CloseFile
USART.Write("Finished.", 13, 10)
EndIf
EndIf
RD
The only code I changed was to ad the Config settings. I found I had to change the default setting of using the internal 32Khz ocilator to get the chip to run at 20MHZ.
Code:
// device and clock...
Device = 18F24J10
Clock = 20
Config
DEBUG = OFF,
XINST = OFF,
STVREN = ON,
WDTEN = ON,
FCMEN = ON,
IESO = OFF,
FOSC2 = ON,
FOSC = HS,
WDTPS = 128
// import SD file system, usart and conversion modules...
#option SD_SPI = MSSP // use hardware SPI
Include "SDFileSystem.bas"
Include "usart.bas"
Include "Convert.bas"
// variables...
Dim Index As Byte
// program start...
SetBaudrate(br19200)
USART.Write("Initialising card...", 13, 10)
If SD.Init(spiOscDiv64) Then
// format SD card...
USART.Write("Formatting, please wait...", 13, 10)
QuickFormat
// write data to SD card...
USART.Write("Writing data, please wait...", 13, 10)
If SD.NewFile("test.txt") = errOK Then
For Index = 0 To 255
SD.Write("Line ",DecToStr(Index,3), 13, 10)
Next
SD.CloseFile
EndIf
// read data back...
USART.Write("Reading data...", 13, 10)
If SD.OpenFile("test.txt") = errOK Then
Repeat
USART.Write(SD.ReadByte())
Until SD.EOF
SD.CloseFile
USART.Write("Finished.", 13, 10)
EndIf
EndIf
RD
-
- Registered User
- Posts: 26
- Joined: Sun Oct 12, 2008 11:21 pm
- Location: Utah