PDA

View Full Version : Picbasic MMC SD : sdfs3.bas



iw2fvo
- 22nd April 2009, 12:22
Hi to all,
I am going to interface an SD MMC card with a pic18f452 programmed with PicBasicPro 2.50. I included the SDFS.BAS program in my basic code.
I then started to modify the SDTEST3.bas in order to make it compatible with my currently used hardware based on 18f452. The pic has a 10Mhz xtal and I enabled the x4PPL to get 40 Mhz clock speed. I did try to slow the clock speed by removing the x4PLL leaving the pic operating at 10 MHZ but with no changes in the operation.
The voltage level has been adapted usinh a three resistors divider ( 1k8 / 3k3 ) as indicated in other projects on the web.
The pic runs correctly, it talks on the serial port with my PC but I still have init : 400, init : 620, init 860, init: 623... errors.
I used 128 M , 256 M and 1 G cards with no improvements.
The three cards work well on my camera.

I attach to this message my modified basic code.
I will appreciate to receive your suggestion, directions, ..help in order to solve the problem.
Thanks in advance.
Ambrogio
IW2FVO

Art
- 22nd April 2009, 12:38
There doesn't appear to be any code attached.

Where did you get the original code for interfacing SD cards if you don't mind my asking?

iw2fvo
- 22nd April 2009, 13:16
I did the procedure to attach the file but it not there !
let me try again
The program has been taken from MeLabs SDFS3.zip.


There doesn't appear to be any code attached.

Where did you get the original code for interfacing SD cards if you don't mind my asking?

iw2fvo
- 22nd April 2009, 13:22
It is me again,
i did the procedure to attach the file but it is still not there.
Any help in attaching it ?
Thanks
Ambrogio



There doesn't appear to be any code attached.

Where did you get the original code for interfacing SD cards if you don't mind my asking?

iw2fvo
- 22nd April 2009, 13:31
try to attach again
Ambrogio




There doesn't appear to be any code attached.

Where did you get the original code for interfacing SD cards if you don't mind my asking?

mackrackit
- 22nd April 2009, 18:46
Try changing this line to not use the hardware.


SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
I think you have the PIC pins mixed up.

And I think you will have better luck if you run the PIC from a 4MHz clock. Then you can run the whole thing from 3 volts and not have to worry with the resistors.

Do you have the SD pins 8 and 9 pulled up to 3 volts? That is also needed.

iw2fvo
- 22nd April 2009, 20:01
Thanks a lot for the instructions:
I will put:
*SDC_UseHardSPI = False
*a new 4 Mhz xtal
* possibly a 3v3 power supply
Yes, pins 9 and 9 have a pull up of 10K to 3v3.
I will let you know the resultsby tomorrow evening .
Thanks again
Ambrogio





Try changing this line to not use the hardware.


SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
I think you have the PIC pins mixed up.

And I think you will have better luck if you run the PIC from a 4MHz clock. Then you can run the whole thing from 3 volts and not have to worry with the resistors.

Do you have the SD pins 8 and 9 pulled up to 3 volts? That is also needed.

iw2fvo
- 23rd April 2009, 17:32
Hi,

I did all the changes... no improvement at all.
The pic has to be programmed at 5Vdc. I then changed the power supply voltage to 3v3. No change.

Thanks
Ambrogio
North Italy




Try changing this line to not use the hardware.


SDC_UseHardSPI = TRUE ' Use hardware SSP port for SPI.
I think you have the PIC pins mixed up.

And I think you will have better luck if you run the PIC from a 4MHz clock. Then you can run the whole thing from 3 volts and not have to worry with the resistors.

Do you have the SD pins 8 and 9 pulled up to 3 volts? That is also needed.

mackrackit
- 24th April 2009, 10:57
What errors are returned?
For example, what do you receive here?


Gosub FSInit
Serout2 PORTC.6, 16780, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]

iw2fvo
- 24th April 2009, 16:23
Hi,
I receive :
" init: 6 2 0 "
" init: 6 2 3 "
" init: 8 6 0 "

and others ... at random.

Thanks
Ambrogio



What errors are returned?
For example, what do you receive here?


Gosub FSInit
Serout2 PORTC.6, 16780, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]

mackrackit
- 25th April 2009, 04:05
I am away from the shop but I think the feed back is telling you the card is not present.

I am sure you have, but double check the hardware.
Are you using a socket for the SD card or some other way. I was using a two row header at first myself and had the problem of getting a good connection at times. Make sur you have the pins aliased correctly, another mistake I have made. :rolleyes:

Do you have a schematic or a good picture of the hardware?

iw2fvo
- 25th April 2009, 07:48
Hi,
I am using a Futurlec mini_board as a card receptacle. The card present LED on the board is on.
The WP and CD disretes at the PIC input are at low level.
I will check the hardware again just to be sure 100%. I will come back again to you as soon as I do have check it.
Thanks again for the interest on my project.
Bye
Ambrogio


I am away from the shop but I think the feed back is telling you the card is not present.

I am sure you have, but double check the hardware.
Are you using a socket for the SD card or some other way. I was using a two row header at first myself and had the problem of getting a good connection at times. Make sur you have the pins aliased correctly, another mistake I have made. :rolleyes:

Do you have a schematic or a good picture of the hardware?

mackrackit
- 25th April 2009, 14:54
Card present is just a switch. I do not use that myself. You could put anything in the socket and make the LED light.

It is used with SDFS if you want to detect a card and force the code to re-initialize for a new card with out a power cycle, "hot swap".

At this time do not use it. Just more stuff to debug.

If you have an 18F4550, or equivalent, to connect like the example might also be a good place to start.

Bruce
- 25th April 2009, 15:58
Just a quess since I don't have your hardware to test;

With the card operating on 3.3V and the PIC on 5V, you should change to a port with
TTL inputs. Or use some type of buffer, or a PIC that will operate on 3.3V at whatever
osc speed you need.

PortC on the 18F452 are Schmitt Trigger type inputs that need higher threshold voltages
for logic 1 than TTL inputs.

iw2fvo
- 25th April 2009, 17:26
Hi Bruce,

I do have a resistor voltage divider 1k8_3K3> to gnd for the signals that go from PIC to MMC. The MMC output goes directly to PIC input portc.4 pin 23.
Could be that the card output level it is not enough to be reconized by the PIC s/t input....
I will really try with a level shifter and 18f452.
Any suggestion for a DIL ( not SMD ) device to be used for voltage shifting ?
Thanks a lot for the help.
Regards,
Ambrogio



Just a quess since I don't have your hardware to test;

With the card operating on 3.3V and the PIC on 5V, you should change to a port with
TTL inputs. Or use some type of buffer, or a PIC that will operate on 3.3V at whatever
osc speed you need.

PortC on the 18F452 are Schmitt Trigger type inputs that need higher threshold voltages
for logic 1 than TTL inputs.

iw2fvo
- 25th April 2009, 17:34
I do not have the pic18f4550 in m hands now.
Do you use the SDFS program or do you have other programs in basic ?
Have you a timed bit interface declaration for the MMC SD ?
Any time history diagram available just to try with a simple comands and response? Where can I found it on the WEB ? I will like to try with a very simple program ...
I will order that PIC but it will require some time.
Do you have in mind some kind of level shifter DIP ( not SMD ) to be used ?
Thanks
Ambrogio





Card present is just a switch. I do not use that myself. You could put anything in the socket and make the LED light.

It is used with SDFS if you want to detect a card and force the code to re-initialize for a new card with out a power cycle, "hot swap".

At this time do not use it. Just more stuff to debug.

If you have an 18F4550, or equivalent, to connect like the example might also be a good place to start.

Bruce
- 25th April 2009, 17:36
Hi Ambrogio,

Page 10, Figure 2 is a really simple bi-directional level shifter for 3.3V to 5V systems.
http://www.standardics.nxp.com/support/documents/i2c/pdf/an97055.pdf

If you have a couple BS170 or similar on-hand, this one works, and it's cheap.

iw2fvo
- 25th April 2009, 18:30
Bruce,
it is a clever and inxpensive system.
If I am not wrong, I do have to put the level shifter from the data out of the card ( pin 7 ) to the input of PIC (pin 23) that has a higher VinH because of the S/T input type. It is more than 3v3.
I will have the BS170 by monday evening.
Additional question: where can i found the MMC digital interface declaration ?
I will like to examine a time history diagram from which I will learn to do with simple instruction ...
> when the SS has to be set hi or lo?
> same thing for SI, SO, CLK and so on . At the moment I am not able to find those kind of information .Those data are normally declared for all type of IC's I used up to now : where are the mmc interface data history ?
Thanks very much
Ambrogio
North Italy



Hi Ambrogio,

Page 10, Figure 2 is a really simple bi-directional level shifter for 3.3V to 5V systems.
http://www.standardics.nxp.com/support/documents/i2c/pdf/an97055.pdf

If you have a couple BS170 or similar on-hand, this one works, and it's cheap.

Bruce
- 25th April 2009, 19:27
I'm not 100% sure if this what you're looking for, but Jan Axelson has a book titled
USB Mass Storage that covers MMC & SD cards.

http://www.lvr.com/usbmstoc.htm

Scroll down the page for a list.

You might also want to signup at http://www.jedec.org if you're looking for manuals, docs,
etc.

iw2fvo
- 27th April 2009, 15:03
Hi to all in the forum ,

Before starting with the hardware changes, I try with a program found on the web. I modified it for my hardware and it seem to me it is at least initializing the MMC properly.
The program is : MMC_POST[1] from Gary Warner. The modified one is attached. you can also find attached the terminal screen capture.
My system does not have the external EEPROM so i think this is the reason for which it does not go on...
I think it was not an hardware problem : >> What do you think ?
I will modify the program to avoid external EEPROM to see if it goes on.
Any comment ?
Thanks
Bye
Ambrogio
North Italy





I'm not 100% sure if this what you're looking for, but Jan Axelson has a book titled
USB Mass Storage that covers MMC & SD cards.

http://www.lvr.com/usbmstoc.htm

Scroll down the page for a list.

You might also want to signup at http://www.jedec.org if you're looking for manuals, docs,
etc.