Hey! I am doing a project (bachelor thesis) with the K64F. (Regulation/Testing of an active load). I want to be able to store data somehow, and I would like transfer it over SD-card. I don’t have a lot of knowledge about coding, and would like an example of how to set it up. I tried finding it in SDK (v3), but it seems there is no example for SD with this microcontroller. I’m coding in Keil (uvision) and was hoping to hear if someone had an example they cared to share! Best regards, Runar.
解決済! 解決策の投稿を見る。
Hi Runar,
Did you add the heard file path in the MDK options?
project->options->c/c++->include paths, please add the fatfs file path, then compile it again.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I see what my problem is now; I'm working in KDSK 1.3 and not 2.0... I suspect there is no SD-card example for MDK KSDK 1.3? I geus I either have to rewrite everything using the libraries in KDSK 2.0 or rather not use the SD-card function.
I will see if I can use the examples given to build my own code, and I’l post here if there is any success.
Edit; Playing around with KDSK 2.0, i try to use tx to communicate between board and display (newhaven). I made it work with KDSK 1.3, setting uart 3 and baud rate of 9600, as well as setting PTC17 as output pin. Tried the same for KDSK 2.0 with no sucess. Any suggestions here?
Thank you so much!
Have a nice day
Hi Runar,
Your problem is the SD initialize question.
Now we already have the MDK KSDK fat code in our KSDK2.0, please go to this link:
Welcome to Kinetis Expert | Kinetis Expert
Click build a ksdk and choose the FRDM-K64 board.
After you download the sample code package, you will find the project in folder:SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\sdcard_fatfs\mdk
Please try it on your side.
Any question, please let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Pardon the confusing, i see i failed to explain it properly.
There is no errors regarding building the program, though while I try to run it, i get the error message:
--------------------------------------------------------
SD Card inserted
Initializing SD Card...
"Failed to initialize SD disk"
--------------------------------------------------------
And the program stops. I tried commenting out the function, and then it runs until if(fr)...
[C#] void log_values() { FRESULT fr; /* FatFs return code */ DRESULT ds; /* Di - Pastebin.com
I added the code I use (removed everything i dont need). Im running 'SD_kort' as its own function instead of having it in main.
If you got any suggestion id appericate it greatly!
Thanks for the help!
Best regards Runar
Hey Jingjing.
I have some problems with the two functions (in running mode);
-------------------------------------------------------------------------------------------------------------
ds = disk_initialize(SD);
if(ds)
{
printf("\nFailed to initialize SD disk\r\n");
for(;;){}
}
-------------------------------------------------------------------------------------------------------------
and;
-------------------------------------------------------------------------------------------------------------
fr = f_open(&fil, "logdata.txt", FA_WRITE | FA_OPEN_ALWAYS);
if(fr)
{
printf("\nError opening text file\r\n");
for(;;){}
}
-------------------------------------------------------------------------------------------------------------
The if sentence is running constantly, printing the error. Is it software related or related to the sd-card?
The other ones are running fine except this one. Got any ideas what the problem may be?
Best regards
Runar
Hi Runar,
You said:The if sentence is running constantly, printing the error.
Do you mean, if run it the first time, it has no error, but if you run the open code constantly, it will printing error.
Take care, after your open the file, you should close it before the next open.
so please modify your code like this:
ds = disk_initialize(SD);
if(ds)
{
printf("\nFailed to initialize SD disk\r\n");
for(;;){}
}
fr= f_mount(0, &fs); |
if(fr)
{
// printf("\nError mounting file system\r\n");
for(;;){} |
}
-------------------------------------------------------------------------------------------------------------
and;
-------------------------------------------------------------------------------------------------------------
fr = f_open(&fil, "logdata.txt", FA_WRITE | FA_OPEN_ALWAYS);
if(fr)
{
printf("\nError opening text file\r\n");
for(;;){}
}
fr = f_close(&fil);
if(fr)
{
printf("\nError closing text file\r\n");
for(;;){}
}
Please try it again!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hey Jingjing.
So your including worked. Somehow I included the files in an inproper way that my compiler didnt like. I added the .c files after I had changed the file path. (Also i had to include "stdint.h" to diskio, but i may have managed to delete that when trying to find a solution. Thanks for the help! Have a nice weekend!
Best regards
Runar
Hey again!
So I tried deleting the files and implementing them the way you suggest, though with lack of any success. I still get the same errors.
It seems as my files is compiling fine, but when the "linking" (when compiling) shows up, I get the errors. I tried commenting out the ff.h, giving me a lot of erros is my main file which doesn’t pop up when having it there. (So it seems as its included correctly?).
I tried deleting all the code from the main; expect initalizing functions and “ds = disk_initialize(SD)”, giving me the same error as previously…
If you have any advice on what to do, I’d appreciate it! Thanks for the help!
Regards
Runar
Hey again Jingjing. Thank you for taking the time with me.
So what i've done over the last couple of days, is trying to implement the files needed to run the program. I've managed to put the ff.h, diskio.h and ffconf.h aswell as the needed fsl. files into Keil. (The headers files is included and defined into main.c).
Though when I try to compile it, it seems as it does not find the ff header files for some reason and I get the following errors:
//Im using the dac_adc_demo as base.
debug\dac_adc_demo.out: Error: L6218E: Undefined symbol f_chdrive (referred from demo_state_machine.o).
I get this for disk_initialize, f_close and some other errors defined in the ff files. (6 all togheter and a “Not enough information to list image symbols”.
I "googled" my erros, and what I concluded with was that I had implemented it wrong, forgot to implement the .c files somehow?
What I did when I included the files, was copying them and adding them to the folders where dac_adc_demo files is. Is there something that I have forgotten to do? I have also stripped down the SD-demo to only include what I need to test. If you got any ideas on what to do/read up on? I’m happy to try anything, cause at the moment I'm kinda blank.
Again, thanks for taking the time with me!
Best regards Runar
Hi Runar,
Did you add the heard file path in the MDK options?
project->options->c/c++->include paths, please add the fatfs file path, then compile it again.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hey. Thanks for your reply.
Is it possible to use this example in Keil aswell?
Hi Runar,
I don't have the SDcare keil project now, but you can use the KSDK keil project, and put this SD card code to the keil project.
You can try it on your side, it is not difficult.
If you have any question in your keil project migration, you can let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Runar Haaskjol,
Please refer to this document:
FatFs + SDHC data logger with KSDK in Kinetis Design Studio
This document is the SD card KSDK code, the project is the KDS project, the test platform is FRDM-K64.
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------