SPI FATFS KEA128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI FATFS KEA128

1,120 Views
emilioaronmoyer
Contributor III

Hello,

 

I'm trying to write to .txt file on a SD card using SPI and FATFS. Right now I can only write raw data to the SD. I found some examples (libraries) on but I cannot connect the two program. Does anyone one have libraries for FATFS for the Kinets KEA128 or similar board?

or does anyone have and idea what do i need to do to write a .txt file?

I have no idea how to link both programs.

I'm using and adafruit adapter for the sd.

I attached my project y the library of fatfs

Original Attachment has been moved to: Copy-of-SPI_SD.rar

Original Attachment has been moved to: ff11a.rar

0 Kudos
3 Replies

601 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Emillo Aron Moyers,

    I find you already ask this question in your another post:

https://community.freescale.com/message/617077#comment-617077

  And our colleague already reply you, about the FATFS lib, you can refer to the KSDK1.3.0.

  After you download the KSDK1.3.0, and you can find the FATFs in the path:C:\Freescale\KSDK_1.3.0\middleware\filesystem\fatfs

  There still have another post about the Fatfs, but is is for K series, you also can refer to it:

FatFs + SDHC data logger with KSDK in Kinetis Design Studio

When you add the Fatfs file, you just need to use f_open function  to create a .txt file, then use the f_write function to write the new code to the text file.

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

601 Views
emilioaronmoyer
Contributor III

Hello Jingjing,

I add this 5 files to my project in coe warrior pastedImage_1.png there is no error wheni build it. I write this code in the main part

#include "derivative.h" /* include peripheral declarations */

#include "CLK.h"

#include "SPI.h"

#include "typedefs.h"

#include "SD.h"

#include "ff.h"

#include "diskio.h"

static UINT8 errorSD;

static UINT8 errorwrite;

static UINT8 errorread;

static UINT8 errorFAT;

static UINT8 datos[512];

static UINT8 datosr[512];

static FRESULT fr1;

static FRESULT fr2;

static FRESULT fr3;

static FIL fil;

int main(void)

{

  int counter = 0;

  unsigned char FILE_NAME[9]="text5.txt";

  FATFS FatFs;

  int i;

  for(i=0;i<256;i++)datos[i]=i;

  for(i=256;i<512;i++)datos[i]=511-i;

  for(i=0;i<512;i++)datos[i]=45;

  Clk_Init();

  initSPI();

  errorSD=SD_Init();

  if(errorSD==0){

  fr1 = f_mount(SD, &FatFs);

  fr2 = f_open(&fil, "log_data.txt", FA_WRITE | FA_OPEN_ALWAYS);

  fr3 = f_close(&fil);

  

  }

  for(;;) {

    counter++;

  }

  return 0;

}

I create fr1, fr2 and fr3 to sea the error in each step of f_mount, f_open and f_close and i got this result:

pastedImage_9.png

What I don't understand is how to link the SPI initialitation of the card and this 3 funtions. Where can I say to this functions to use the spi that I already configure?

I attache the project.

Regards,

Emilio

0 Kudos

601 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Emillio Aron Moyers,

    If you want to connect your SPI interface to the Fatfs, you need to modify your disk interface function to connect your SPI function.

    The interface function contains: disk_initialize, disk_status, disk_read, disk_write,disk_ioctl, get_fattime.etc.

    You can find these function in diskio.c, diskio.h , ff.c, ff.h。

    More details, you can go to the Fatfs official website, there has some sample code, but not for kinetis, even not for kinetis, you still can refer to it:

FatFs - Generic FAT File System Module

Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos