0
\$\begingroup\$

Hi I am working on STM32F103c8t6 MCU.I am trying to run sd card with spi wiht this library https://github.com/eziya/STM32_SPI_SDCARD do every thing like youtube video and my connection is like video https://www.youtube.com/watch?v=spVIZO-jbxE&t=321s. This is a part of my cod:

send_uart("SD program ready....\r\n");
    
DSTATUS my_status = SD_disk_initialize(0);
 if(my_status == STA_NOINIT ){
    send_uart ("error in initializing SD CARD...\n");
 }else send_uart ("SD initializing OK...\n");
 
 if (my_status == STA_NODISK){
    send_uart ("No medium in the drive...\n");
 }
 if (my_status == STA_PROTECT){
    send_uart (" Write protected...\n");
 }
 
 fresult = f_mount(&fs, "0:", 1);
sprintf(buffer,"mounting SD CARD result:%d\n",fresult);
send_uart(buffer);  

/* Create second file with read write access and open it */
fresult = f_open(&fil, "file2.txt", FA_CREATE_ALWAYS | FA_WRITE);
sprintf(buffer,"open SD CARD result:%d\n",fresult);
send_uart(buffer);  

strcpy (buffer, "This is File2.txt, written using ...f_write... and it says Hello from 
Controllerstech\n");
fresult = f_write(&fil, buffer, bufsize(buffer), &bw);
sprintf(buffer,"write SD CARD result:%d\n",fresult);
send_uart(buffer);  
 

This is my response from uart:

SD program ready....
SD initializing OK...
mounting SD CARD result:1
open SD CARD result:1
write SD CARD result:9

return SD initializing OK.. but mounting SD CARD result:1 that means FR_DISK_ERR. What is the problem ? Iam using a SD module that has a 5v to 3v level shifter ic it can cuse problem?

enter image description here

\$\endgroup\$
6
  • \$\begingroup\$ Have you tried different SD cards? Some manufacturers don't implement SPI mode very well in their SD cards. \$\endgroup\$ – brhans Jul 11 '20 at 13:22
  • \$\begingroup\$ I tried this module and this SD card with arduino it worked very well \$\endgroup\$ – OnlyStar Jul 11 '20 at 13:36
  • \$\begingroup\$ Have you followed all the instructions here on eziya76's blog using the STM32CubeMX tool to generate your project and then adding/editing all the relevant driver code? \$\endgroup\$ – brhans Jul 11 '20 at 13:46
  • \$\begingroup\$ Yes I a mention in description I do every thing like video .when I do not insert SD card f_mount returned FR_NOT_READY .And initializing of SD card returned ok. \$\endgroup\$ – OnlyStar Jul 11 '20 at 16:38
  • \$\begingroup\$ Compare the steps you've followed from the video with everything written down in the blog. Make sure that nothing is left out. \$\endgroup\$ – brhans Jul 11 '20 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.