Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months 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
- include "mbed.h"
- 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:
2 Answers
9 years, 8 months 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 28 Mar 2015Please 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 29 Mar 2015Thanks 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 29 Mar 20159 years, 7 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.
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 15 Apr 2015Hi 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 15 Apr 2015Hi,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 17 Apr 2015Hi,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 19 Apr 2015Hi,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.
posted by 21 Apr 2015Hi 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 22 Apr 2015Hi 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 23 Apr 2015Hi 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 23 Apr 2015Hi,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 25 Apr 2015Hi 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 26 Apr 2015HI,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.
posted by 27 Apr 2015Hi Writer, Thanks for everything.
Here is map how I've connected them (6 pins on red background - pins from my board with sd shield)
With best regards, Arseniy
posted by 27 Apr 2015Hi,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.
Regards, ImageWriter.
posted by 29 Apr 2015Hi Writer,
Thanks for your reply. What's the signal wire? MISO?MOSI?
With best regards, Arseniy
posted by 04 May 2015Hi,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.)
Regards, ImageWriter.
posted by 04 May 2015Hi 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 05 May 2015Hi,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 06 May 2015Assigned to
8 years ago.This means that the question has been accepted and is being worked on.
Please tell us what errors you are getting. And post a link to what SDFileSystem you are using.
posted by David Fletcher 28 Mar 2015SDFileSystem 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