<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SD card interfacing</title><link>/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><description>Hi,
I have written SD &amp;amp; SDHC card routine for reading, writing and erasing data from SD card. It used the hardware SPI of nRF51822.
NOTE:
1)Define the PINs of SD card first before initialing.
2)Define MOSI, MISO and SCK pins only, define the ...</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Tue, 04 Jul 2017 08:18:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>YASH</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi. Which SDK is this for interfacing SD card? I tried the one with SDK 10, but nothing worked out, I am getting error in the file nrf_spim.h where it says NRF_SPIM_TYPE is undefined. Please help fix this?&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Tue, 20 Dec 2016 11:27:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Ankush</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi All,&lt;/p&gt;
&lt;p&gt;I just seen this post and it seems to be useful to me. I tried the earlier approach specified in above two library files using SPI. I interfaced NRF52 with SD card.&lt;/p&gt;
&lt;p&gt;In first approach, I have tried with SD card and SDHC card. In both cases initialization failed massage came. I am using library files specified by Stanislav Silnitskiy .&lt;/p&gt;
&lt;p&gt;I tried FATFS example to interface SD card with nrf52. It works fine . But for writing at high rate based on SAADC interrupt, I am getting some issues specified at &lt;a href="https://devzone.nordicsemi.com/question/107383/how-to-write-to-sd-card-at-high-rate/"&gt;this link&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My code with fatfs is specified at above mentioned link.&lt;/p&gt;
&lt;p&gt;Does any one has any idea why I am getting these issues and how Can resolve them?&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Thu, 08 Dec 2016 15:52:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Lea</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Thanks a lot, the example is very helpful, everything works with the new libraies from SDK12.2.0.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Thu, 08 Dec 2016 12:03:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Ole Bauck</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Just mentioning that the newest SDK (12.2.0) has support for SD cards. I advise you to take a look at the SD card example &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/app_sdcard_example.html?cp=4_0_0_4_5_30"&gt;here&lt;/a&gt;. If you have questions to the SD card library/example in the SDK, you can post a question on the forum and we will help you. The SD card library in the SDK is also based on FATFS.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Wed, 07 Dec 2016 15:29:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Lea</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thanks a lot Kumar for sharing your code.
I try to use the FatFs with your library on an nRF52 developer board to communicate over SPI with a SD Card.&lt;/p&gt;
&lt;p&gt;But I&amp;#39;m facing some problems trying to write something in a text file on the SD Card.
Initialzing the Card and create, open or read a text file works. But when I want to write in my text file   the file stays empty. There is no error message in the return value of the f_write function but the f_close function returns FR_DISK_ERR. While debugging I see that in my code  the Bytes I want to write in the File are even in the Buffer of the file variable. But when I read out the Card on my PC (with a text editor) the text file is still empty.&lt;/p&gt;
&lt;p&gt;When I write something in my file from the PC and save it, the next time I try to write over SPI on the Card the Bytes that already exists are overwritten by the new values I want to write. But only the ones who already exist are overwritten and no additional Bytes. In this case the f_open function returns FR_OK.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my code (I use the state variable only for debugging):&lt;/p&gt;
&lt;pre&gt;int main(void)
{

	BYTE data[512];
	FATFS FatFs;       /* FatFs work area needed for each volume */
	FIL Fil;           /* File object needed for each open file */


	UINT data_len = 64;
	UINT bw;
	uint8_t state=0;

	bleStackInit();
	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);


	memset(data, 97, sizeof data);
        sd_spi_init();

	while(1)
	{
		
		f_mount(&amp;amp;FatFs, &amp;quot;&amp;quot;, 0);  /* Give a work area to the default drive */

		/* Opens an existing file. If not exist, creates a new file. */
		if(f_open(&amp;amp;Fil, &amp;quot;logfile.txt&amp;quot;, FA_WRITE| FA_READ | FA_OPEN_ALWAYS)!= FR_OK)
		{
			state= 4;
		}


		if(f_write(&amp;amp;Fil,data,data_len,&amp;amp;bw)!= FR_OK) //f_printf(&amp;amp;Fil, &amp;quot;%d&amp;quot;, u)
		{
			state=2;
		}

		/* Close the file */
		 if(f_close(&amp;amp;Fil)!= FR_OK)
		 {
			 state=3;
		 }
		nrf_delay_ms(1000);

		if(state)
		{

		}
	}

}
&lt;/pre&gt;
&lt;p&gt;I&amp;#39;m using a 32 GB Sd Card. I have no other slaves for this SPI than the Card that&amp;#39;s why my CS (SS) Pin is set on ground.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m thankful for any advice.&lt;/p&gt;
&lt;p&gt;Regards Lea&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Tue, 27 Sep 2016 12:58:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Ole Bauck</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Great library Kumar (and of course you Salman). Do you mind making a new blog with link to this code which uses the filesystem? This would make it easier for people to see it. Have a link to &lt;a href="http://elm-chan.org/docs/mmc/mmc_e.html"&gt;this&lt;/a&gt; for the hardware connections.&lt;/p&gt;
&lt;p&gt;I had problems when using nRF52, which was caused by &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev1.errata/anomaly_832_58.html#anomaly_832_58"&gt;this errata&lt;/a&gt;. The solution was to use SPI0 instead of SPIM0 (#define SPI0_USE_EASY_DMA 0). Implementing the workaround should also work.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Fri, 09 Sep 2016 15:56:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Lalit Kumar</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In case anybody still require FAT system, I&amp;#39;ve put it &lt;a href="https://github.com/katphlab/nrf_fatfs"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Thu, 08 Sep 2016 07:47:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Bart</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Above problem is solved&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Mon, 05 Sep 2016 15:09:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Bart</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hello people,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using the NRF52 PCA 10040 (S132) devkit for some time now and I&amp;#39;ve soldered a micro SD card holder to 4 pins configured as SPI using SDK 11 with the code above. The DO has a 16k ohm pull-up to VDD, no other pins have pull-up or down.
Whatever I do using this example code or different example code variants found all over the net, I do not get any level change of the card on the DO pin.
I even used a different SD card holder connected to a different set of pins, use SPI 0, 1 and 2 controller, different delays, 125 and 250 kHz, SPI mode 0-3, different CS toggle initialization strategies, sending extra idle clocks, 4 different SD cards of 2, 8 and 16 GB, all different brands, no change on DO whatsoever.
I&amp;#39;ve ordered some more SD cards of different brands to test with in the next couple of days but have little hope this will bring me closer to a solution.
One thing I&amp;#39;ve noticed is that the NRF52 only supplies 2.8-2.9 volts on VDD or any other output pin.
I&amp;#39;ve therefore used an external 3.3V power supply and sent CMD8 as initialization and saw a reply from the card on the DI channel, making it kind of bi-directional...&lt;/p&gt;
&lt;p&gt;Hope anyone has a clue ? Kind regards, Bart.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Thu, 10 Dec 2015 02:16:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Stanislav Silnitskiy</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;for lazy ones: see attached, ported to SDK 10&lt;/p&gt;
&lt;p&gt;Stan&lt;/p&gt;
&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-00-04-DZ-391/4643.SD_5F00_Routines.c"&gt;SD_Routines.c&lt;/a&gt;
&lt;a href="/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-00-04-DZ-391/7380.SD_5F00_Routines.h"&gt;SD_Routines.h&lt;/a&gt;&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Tue, 13 Oct 2015 14:16:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>noe</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Thanks for this code!
For which SDK version is this?
Doesn&amp;#39;t seem to be working with 7.x.x
Thanks in advance&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Sun, 29 Mar 2015 21:18:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Mihail</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nico, See &lt;a rel="nofollow" target="_blank" href="https://github.com/MiBLE/SST25VF064C_with_nRF51822"&gt;github.com/.../SST25VF064C_with_nRF51822&lt;/a&gt; it is written for flash memory but maybe useful for you.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Fri, 06 Feb 2015 12:18:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Nico</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I want to write on an SD card and I tried to use your files  but i faced some problems.
First, the functions spi_master_init(SPI0,SPI_MODE0,0) and spi_master_tx_rx( SDCard_spi ,1, spi_txbuf, spi_rxbuf) were not existing anymore in the current API (&lt;a rel="nofollow" target="_blank" href="http://developer.nordicsemi.com/nRF51_SDK/doc/7.1.0/s110/html/a00767.html#ga3cf5563d474f5b41080b6ae53be0ee51)"&gt;developer.nordicsemi.com/.../a00767.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So I changed the functions to spi_master_open(SPI_MASTER_HW, &amp;amp;spi_config) and spi_master_send_recv(SPI_MASTER_0,spi_txbuf,2,spi_rxbuf,2) but now I&amp;#39;m facing a new problem concerning the linking step:&lt;/p&gt;
&lt;p&gt;Error: L6218E: Undefined symbol app_error_handler (referred from spi_master.o).&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know how to solve it. I included the library app_util_platform.h too.&lt;/p&gt;
&lt;p&gt;Thank you in advance. Best regards.  &lt;a href="/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-00-04-DZ-182/0336.SD_5F00_Routines.c"&gt;SD_Routines.c&lt;/a&gt;&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Tue, 13 Jan 2015 16:55:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>gijs</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Thanks a lot for sharing these routines. This saves me a lot of time!&lt;/p&gt;
&lt;p&gt;I think I found a small error in the read and write functions. For an SDHC card the address equals the sector number. For SDSC cards the address equals the sector number multiplied by 512. The current code is targeted to SDSC cards only.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: SD card interfacing</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/sd-card-interfacing</link><pubDate>Thu, 08 Jan 2015 15:18:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96687dad-b0ef-497f-82db-2bb49312be54</guid><dc:creator>Manjunath</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi,
Thanks for replay i worked with this file  it is working fine but i need file system instead of raw read and write.&lt;/p&gt;
&lt;p&gt;any  how thanks for  your replay.&lt;/p&gt;
&lt;p&gt;Regards
Manjunath N N
(India)&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=755&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>