Jump to content
  • 0

PMOD uSD Cant write to multiple lines


NeedlessBird

Question

So for my senior design project we're using a microblaze to poll a number generator and then write that data to an SD card. I've adapted the demo code provided in the PMOD microsd driver files to take input variables and write them to a string. Then I take that string and write it to the SD card. My problem is that no matter what I try I can't print to multiple lines. I've looked in the DFATFS.h file where all the functions are abstracted but I'm at a bit of a loss. I'll attach a text file containing the subroutine that writes to the SD card (it gets called when ever there is a new value to write). Let me know if theres any other details i didn't provide.

sd write.txt

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

A follow up, I've tried to use file.fslseek(file.fseof()); before I run the file.fswrite() function but it still doesn't write to the end of the file. The file is opened with fr = file.fsopen("name.txt", FA_WRITE | FA_OPEN_ALWAYS); where fr is the FSTATUS variable.

Link to comment
Share on other sites

Hi @NeedlessBird,

Could you provide more detail such as the contents of the file on the SD card. 

To clarify are you having issues opening a previously created file and adding to the eof?

or is the main issue trying to write multiple lines of data to the SD at one time?

best regards,

Jon

 

 

Link to comment
Share on other sites

1 hour ago, jpeyron said:

Hi @NeedlessBird,

Could you provide more detail such as the contents of the file on the SD card. 

To clarify are you having issues opening a previously created file and adding to the eof?

or is the main issue trying to write multiple lines of data to the SD at one time?

best regards,

Jon

 

 

Thanks for the reply Jon,

I have a subroutine that scans a random number generator. When a new value is detected it calls the SD print function. The print subroutine only prints one line to the SD card, but instead of printing to the EOF it overwrites the same line every time. The project uses DFATFS.h which includes fs_ff.h, the version DFATFS.h is from 2015 and the version of fs_ff.h is from 2014. I noticed that fs_ff.h doesn't have FA_OPEN_APPEND defined, according to the folk over at StackOverflow told me that opening the file with the mode FA_WRITE | FA_OPEN_APPEND will let me write to the EOF. I've tried replacing the fs_ff.h with the latest version of ff.h but the SDK throws errors when i build it.

Link to comment
Share on other sites

So it looks like the version of DFATFS and fs_ff that Digilent provides in the PMOD SD library doesn't support FA_OPEN_APPEND. Is it possible to write to the end of the file using the packaged version from the vivado-master-master repository? Or will I have to create new files anytime I want to write new data?

Link to comment
Share on other sites

Hi @NeedlessBird,

I found a stack overflow thread here that uses the older library that might be helpful with adding data to the eof on the SD card. One suggestion is to flush the buffer before closing.

Please attach a screen shot of the SDK errors you are getting when replacing the fs.ff.h file.

best regards,

Jon

Link to comment
Share on other sites

22 minutes ago, jpeyron said:

Hi @NeedlessBird,

I found a stack overflow thread here that uses the older library that might be helpful with adding data to the eof on the SD card. One suggestion is to flush the buffer before closing.

Please attach a screen shot of the SDK errors you are getting when replacing the fs.ff.h file.

best regards,

Jon

Attached is a screenshot of the problems window in the SDK. This was accomplished by replacing the code in fs_ff.h and fs_ff.c with the code in the new version of ff.h and ff.c, there are a lot of errors being thrown by the DFATFS.cpp file.

errors.PNG

Link to comment
Share on other sites

So i did manage to get the multiple line print error fixed. By keeping track how how many bytes are being written to the card and then seeking by that amount I am able to print to the end of the file. It's not the most elegant solution but it works.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...