Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12597 Discussions

Writing .txt file in SD Card - DE2

Altera_Forum
Honored Contributor II
6,593 Views

Hello, I am Student from a University beginner in FPGAs, and I was doing a project with Nios II that uses a Altera DE2 Board to do some operations and save the results. The main ideia was to transmit to computer the results, but the USB take too much time to the FPGA. 

Now I am seaching a way to save those results at the SD card. But I couldn't find a way to store data in SD card. My idea was to create a .txt file that could receive at the end of each operation a value in the next line. 

If someone knows how save values in the SD card, I really appreciate your help, if you help send me.
0 Kudos
37 Replies
Altera_Forum
Honored Contributor II
1,469 Views

When I transfer data, I use a very simple and relatively fast connection via GPIO and Labview. For that you need a Labview card and box (expensive but in most university labs available) with digital I/O pins and a clock input. Then you connect the I/O pins from Labview to some pins of the GPIO port. 

The transfer rate is 1Mbit/s for each connected data pin with my labview card. 

 

I tried to write to the SD card once, but failed when my SD card was not even recognized by the board. There is also no example to actually write to the SD card, only to read from it.
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Does anyone have a method of writing to th SD card without using LabView?

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

You could start with the DE2_115_SD_CARD demonstration project: it includes a function SDHAL_WriteData in the file sd_hal.c. You might be able to write using this function, if you find an SD card that is recognized by the board. 

I see that this demonstration is for the DE2-115 board; hopefully there is a similar demonstration for the DE2 board.
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Awesome. Thanks for the advice I will have to take a look at the code. Do you know if there is a link on the altera website for the demonstration files? I can't seem to find them. 

 

What exactly is the trick to find an SD card that is recognized by the DE2 board? SDHC? Non SDHC? MicroSD into adapter? Certain brands?
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

you can find the files here: http://www.terasic.com.tw/cgi-bin/page/archive.pl?language=english&categoryno=139&no=502&partno=4 

In order to download, you need to sign up for a Terasic account.
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

What is the trick to finding an SD card that is recognized by the DE2 board? I've tried two cards now (PNY and Sandisk both 2GB) and neither one is being recognized.

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

I would ask Terasic (I think it's support@terasic.com); they should know, because they ship the high end boards with SD cards.

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Hello everyone! I really appreciate your help! 

 

David Pavid: I don't have a labview card, but its a nice idea! 

 

I adapted the code for the DE2-115 to run in DE2. I am running the program but I am having problems with the sd card that is not being recognized. 

I tested 2 SD cards, both microSD into adapters, and both fail. (1gb KINGMAX microSD and 8gb microSDHC Class4 that doesn't says the brand). 

 

Anyone has already tested a old simple card (32-128mb) and without adapters? 

 

I am going to contact terasic, if I get answers I post here.
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

The SD card (2 GB ) that came with the DE4 card can be mounted by the demonstration project design. Therefore I don't think that it is the size of the SD card.

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Hello! I'm still trying to write a .txt file in SD Card. I searched a lot in internet but I couldn't find the solution! 

If someone knows a way please tell! 

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Not to get too far off topic here but does anyone know of a way to write to an SD card using SPI (low level write)? As long as you know what data is being written you could extract it using MATLAB. Any thoughts?

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Hello! I'm need a way to save data from fpga. I couldn't find a easy way to store in SD card. Does anyone have some idea to transfer data in a quicker way?

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

If you always run your system with a USB cable attached, you could use the host file system software component, that will let you read/write files on the PS from the embedded application. You need to run in debug mode though.

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Found the solution to the mysteries of the SD Card! 

http://www.alteraforum.com/forum/showthread.php?t=34101
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

PeteCSI, thank you for your support!!! 

 

I'm I going to try the method! After testing it, I post here my results!
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Hello! It's possible to write data in a pendrive/flash device? using USB host? 

 

PeteCSI: I'm trying to understand the FreeRTOS! When I get something I post here my results!
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

You'll need quite a lot of USB driver code in order to access a USB drive. 

You'll also need fairly trivial (by comparison) code to access the FAT32 filesystem on the device.
0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

On my DE2-115 it says it only accepts SD formatted on FAT16.

0 Kudos
Altera_Forum
Honored Contributor II
1,469 Views

Larger devices are much more likely to have FAT32 (than FAT16). The crossover point is probably abut 128MB - although FAT16 can go higher. 

Nothing to stop you reformatting part of the device with FAT16 though.
0 Kudos
Altera_Forum
Honored Contributor II
1,307 Views

PeteCSI: I'm having some trouble when creating a NIOS with the Altera_UP_SD_Card, I tested the .c example using a Nios from the Altera CD, but I get no response from SD.

0 Kudos
Reply