cancel
Showing results for 
Search instead for 
Did you mean: 

SPI configuration problem on STM32F4 Discovery

cagibomber
Associate II
Posted on August 07, 2012 at 18:55

Hi everyone,

I am trying to send some bytes of data on a sd-card (8GB) using SPI.

I started with wiring the sd slot and configuring the spi but I have nothing, not even the clock...

I have followed what's explained in the file spi.h and seen other post about spi but I still don't see where I am wrong.

I'd really appreciate if you can help me with it ! Thank you.

#spi-sd-card-stm32-discovery
33 REPLIES 33
cagibomber
Associate II
Posted on August 08, 2012 at 19:27

Ok great, I should be good since I just have to write a line every 5 minutes...

I try like that.

There's something I didn't understand with your fatfs example :

You're writing in a txt file but you don't load it, right ?

Where does it go ? I don't see it anywhere.

Thank you.

Posted on August 08, 2012 at 19:45

I wrote the file to the SD card, so the file can be examined when the card is later plugged into a PC. I'm not sure of the merit of loading the file? I read the MESSAGE.TXT to demonstrate reading and computing a file length.

It was done this way so the board could be run head-less (ie without an LCD or serial output), but you could still tell if it accessed the card and used FATFs successfully.

I have a serial port connected to my STM32F4-Discovery, many people do not.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cagibomber
Associate II
Posted on August 09, 2012 at 00:29

Ok I see, but in your code I didn't see any SDIO initialization nor GPIO. I guess you just didn't put this bit in the fatfs example, right ?

Ok I'll try this tomorrow now ! 

Thanks a lot for your help !

Posted on August 09, 2012 at 00:47

The SDIO and GPIO are initialized from diskio.c disk_init()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cagibomber
Associate II
Posted on August 09, 2012 at 13:28

cagibomber
Associate II
Posted on August 09, 2012 at 13:35

cagibomber
Associate II
Posted on August 09, 2012 at 13:56

Ok, I found it in discovery.c and discovery_sdio.c !!! I'll take a look at that !! :)

cagibomber
Associate II
Posted on August 09, 2012 at 14:50

I plugged it and launched it, I can observe the command signal sent by the stm32 to the sd card but when I try to read it from my computer, There is nothing ! I reated the 3 txt files in the card and nothing is modified in them ! 

cagibomber
Associate II
Posted on August 09, 2012 at 16:53

More investigation showed that res gets FR_DISK_ERR.

res = f_mount(0, &fs32); <<<<<<<<<<<<<<<< Returns FR_OK 

res = f_open(&fil, ''MESSAGE.TXT'', FA_READ); <<< Returns FR_DISK_ERR

I guess it can only come from '&fil' since the file is in the card.

Or, could it be because of the card type ?

I use a Transcend SDHC card (8GB) class 6.

After the simulation, all fil's arguments are equals to 0, even if I put FA_CREAT_NEW.

Thanks.
Posted on August 09, 2012 at 17:45

Or, could it be because of the card type ? I use a Transcend SDHC card (8GB) class 6.

That or how you have the socket wired up. You'll get errors if the SD card initialization fails, suggest you instrument the code and look at the initialization and card reading code.

I'm using assorted Micro SDHC cards, and I'm using 33K pull-ups based on what was in my parts draw. It is a bit hackish, I have a custom STM32F2 based board with a built-in socket that I do my primary development on, which has a far more considered design.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..