9 years ago.

SD card not found or error opening flie

I have used this code for sd card interface with stm32 f401re bin generated was uploaded and getting above error

using same code there was older bin file which is working pls respond soon

Temperature logging demo - record temperatures to SD card and print them to the console every 10 seconds

  1. include "mbed.h"
  2. include "SDFileSystem.h"

Analog input (pin 15) AnalogIn ain(A2);

USB serial (tx, rx) Serial pc(USBTX, USBRX);

SD card (SPI pins) SDFileSystem sd(D11, D12, D13, D10, "sd");

Timer for our timestamps Timer timer;

int main() {

FILE *file; float voltage_in; float degrees_c; int i; int c;

Start our timer timer.start();

Open file for writing file = fopen("/sd/temp_data.txt", "w"); if ( file == NULL ) { error("ERROR: Could not open file for writing!\n\r"); return -1; }

Tell the user we need to wait while we collect some data pc.printf("\nCollecting data (Do not remove SD Card!) ...\n\r");

Collect temperatures with timestamps every second for(i = 0; i < 10; i++) {

float Temp = ain.read_u16(); Read analog value float voltage_in = (float) 3300 / 65535 * (float) Temp; degrees_c = (voltage_in / 10); fprintf(file, "%2.2fs: %3.1f deg C\n\r", timer.read(), degrees_c); wait(1); }

Close file and re-open it for reading fclose(file); file = fopen("/sd/temp_data.txt", "r"); if ( file == NULL ) { error("ERROR: Could not open file for reading!\n\r"); return -1; }

Print results to console pc.printf("Temperature data:\n\r"); while(1) { c = fgetc(file); if ( c == EOF ) { break; } pc.putc(c); }

Close the file and finish fclose(file); pc.printf("Done! Safe to remove SD card\n\r");

return 0; }

Question relating to:

Please tell us what errors you are getting. And post a link to what SDFileSystem you are using.

posted by David Fletcher 28 Mar 2015

SDFileSystem library link: http://developer.mbed.org/users/mbed_official/code/SDFileSystem/ Error(s): sd card shield no disk, or could not put SD card into SPI idle state There is only one error, which I get when I trying to open file, after this error, code isn't running any more

posted by Arseniy Prosvirin 28 Mar 2015

2 Answers

9 years ago.

You may not be able to use PA_15 as cs, as it is not brought out to the Arduino connector, choose another pin that is connected. It looks to me to be PB_5

Thanks for your quick answer, but PB_5 couldn't be used as CS because this pin is MOSI. And anyway, it doesn't mean that are they on arduino headers or not, because they are connected with SPI pins on SD board, which are located alone

posted by Arseniy Prosvirin 28 Mar 2015

Please take the time to read the user manual for the STM32F401, where you will find that a modern micro controller has pins that are multi function. Just because a pin has label MOSI does not mean it can only be MOSI. The mbed lib makes it easy for you to change the pin function, in your case all you need to do is change PA_15 to PB_5, the SDFileSytem lib changes the function from MOSI to GPIO as required for the cs function. You should also take a look at the circuit for your SD shield, you can find it here http://www.seeedstudio.com/wiki/File:SD_Card_Shiled_v4.0.pdf. The signal you should look for is CS_A, then find what pin this connects to on your nucleoF401, for me this is PB_5. Have fun finding your problem!

posted by David Fletcher 29 Mar 2015

Thanks for your answer, but are you sure that it won't give error 'Pinmap not found for perephiral' agin while uploading code onto shield?

posted by Arseniy Prosvirin 29 Mar 2015

If you are getting that error then you have broken the SDFileSystem constructor, and does not comply with the program you have posted above. Try,

 DigitalOut xxx(PB_5); 

This compiles ok proving PB_5 is a valid pin.

posted by David Fletcher 29 Mar 2015

I'm sorry for long pause, but chaning pin for CS to PB_5 hasn't helped and gives same error: No disk, or could not put SD card in to SPI idle state

posted by Arseniy Prosvirin 11 Apr 2015
8 years, 11 months ago.

Hi,Arseniy. I am a Japanese. And I can't speak English very well. By the way, I write my expectation. You wrote it as "a+" in 24th line. I write "a". I think that "a+" does not work normally. Let's see https://developer.mbed.org/users/ImageWriter/code/SDCard_Aitendo_2p2TFT/file/a81a5af65446/main.cpp. best regards.

Hello Writer, But as I thought, cnaging 'a+' to 'a' hasn't helped

posted by Arseniy Prosvirin 14 Apr 2015

Hi,Arseniy. I changed your cord as follows and tested it.

SDFileSystem sd(D11, D12, D13, D10, "sd");// MOSI, MISO, SCK, CS // Change port number.
//    sd.mount();     // Comment out
//     sd.unmount();  // Comment out

The cord worked normally in my Nucleo F411RE. best regards.

posted by Image Writer 15 Apr 2015

Hi Writer, thank you. I'll try it out as soon as possible, but could you send me a photograph of your 'sandwich' because I probably connect it wrong?

posted by Arseniy Prosvirin 15 Apr 2015

Hi,Arseniy. OK,I see. I tried SD Card Read Write test. It was success.

Let's go my page. I took the photograph of the experiment.

https://developer.mbed.org/users/ImageWriter/code/SDCardNotFound-NoI-found-a-SDCard/wiki/Homepage

posted by Image Writer 17 Apr 2015

Hi Writer, especially, as I can see, you use antoher board or not?

posted by Arseniy Prosvirin 18 Apr 2015

Hi,Arseniy.

I am sorry, I have not a other board. I used a handmaid shield.

By the way,Could you show me a photograph of your Seeed SD card shield ,Nucleo and wiring?

I think that you must be wiring the ISP connector to D10,D11,D12 port.

Regards,

ImageWriter.

posted by Image Writer 19 Apr 2015

Hi, Writer Here it is: /media/uploads/arseniy899/wey9rw91igc-1-.jpg

posted by Arseniy Prosvirin 20 Apr 2015

Hi,Arseniy. Thank you for showing a photograph.

I am sorry if my interpretation is mistaken. Is the wiring not wrong? Please watch the next photograph.

/media/uploads/ImageWriter/img_4901.jpg

posted by Image Writer 21 Apr 2015

Hi Writer, Thanks for your photo. As I can see, everything is correct. Might be problem is in pinnmaping because I've used it on my Arduino(which I can't use for my current project) and there it works well?

posted by Arseniy Prosvirin 22 Apr 2015

Hi Arseniy. Thank for your reply. Because your wiring is not wrong, an answer is not found in me.

I have different suggestion.I created an SD card adapter by myself. If there is the time that is enough for you, I recommend that you make an adapter with oneself in this way.

http://imagewriteriij.blogspot.jp/2015/04/mbedsd.html

Regards, ImageWriter.

posted by Image Writer 23 Apr 2015

Hi Writer,

Thanks for your reply. I'm sorry, but I'm not able to do so. Unfortunately, I already have these board.

With best regards, Arseniy

posted by Arseniy Prosvirin 23 Apr 2015

Hi,Arseniy. It was good that you could solve a problem by using the different board.

I was able to study in various ways this time.

If a problem will occur in the future, please ask me a question.Thank you.

Regards, ImageWriter.

posted by Image Writer 25 Apr 2015

Hi Writer,

You have understood incorrectly, because I can't use Arduino for that project, that means problem still exsits.

With best regards, Arseniy

posted by Arseniy Prosvirin 26 Apr 2015

HI,Arseniy. I'm sorry, I have understood it by mistake.

Does it mean that Nucleo and an SD card do not yet work well? Ok. I see.

Please show me the photograph a little in detail.I want to see wiring of the pins in particular well.

Regards, ImageWriter.

/media/uploads/ImageWriter/wey9rw91igc-1-.jpg

posted by Image Writer 27 Apr 2015

Hi Writer, Thanks for everything.

Here is map how I've connected them (6 pins on red background - pins from my board with sd shield) /media/uploads/arseniy899/iscwm-1-.jpg

With best regards, Arseniy

posted by Arseniy Prosvirin 27 Apr 2015

Hi,Arseniy. Thank for your reply. Your wiring is right. I do not know what is bad.

I suggest one. Please connect the signal to direct ARDUINO connector.

/media/uploads/ImageWriter/459d5b3e-3521-4b28-8bda-3584453f1271.png

Regards, ImageWriter.

posted by Image Writer 29 Apr 2015

Hi Writer,

Thanks for your reply. What's the signal wire? MISO?MOSI?

With best regards, Arseniy

posted by Arseniy Prosvirin 04 May 2015

Hi,Arseniy. Thank for your reply.

What I want to say is,

You wired the "Morpho" connector on Nucleo.It is right.

However, I will be connected to the "Arduino Compatible connector" on the sd shield if it is me.(Of course same pin number.)

/media/uploads/ImageWriter/a.jpg

Regards, ImageWriter.

posted by Image Writer 04 May 2015

Hi Writer,

Thanks for your reply. Do you really think that it will really help? I mean that they are directly connected...

With best regards, Arseniy

posted by Arseniy Prosvirin 05 May 2015

Hi,Arseniy. Thank for your reply.

I don't have any clear proof in regards to that. However, I think that it is one of the solutions.

By the way, do you have an oscilloscope? I think that You can solve the problem by observing four(CS,MOSI,MISO,CLK) signals.

Regards, ImageWriter.

posted by Image Writer 06 May 2015

Assigned to mohan nalabolu 7 years, 4 months ago.

This means that the question has been accepted and is being worked on.