<?xml version="1.0" encoding="UTF-8" ?>
<?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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62338/how-to-disable-uninitialize-spi-on-nrf9160dk-used-for-interfacing-sd-card</link><description>Hello, 
 I interfaced nRF9160 and SD card using SPI. I started with this sample: ncs/zephyr/samples/subsys/fs/fat_fs. 
 Now once the files from SD card are read, I want to uninitialize this SPI, so it can be used by other peripheral. So how can I disable</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Jul 2020 08:34:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62338/how-to-disable-uninitialize-spi-on-nrf9160dk-used-for-interfacing-sd-card" /><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/260294?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2020 08:34:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:043bdfad-415e-4000-9352-85fe7b2e8492</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I solved the issue. Now I am able to disable and enable the SPI peripheral used for SD card as many times as I want. I used device power management for SPI and cleared the CS pin separately by writing into the register&amp;nbsp;NRF_P0_NS.&lt;/p&gt;
&lt;p&gt;Thank you so much for your help.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Jagruti&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/259402?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2020 09:58:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:788624c5-4ac6-4a29-9f7f-533f699fcf64</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi again,&lt;/p&gt;
&lt;p&gt;I tried to implement&amp;nbsp;&lt;span&gt;DEVICE_POWER_MANAGEMENT.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But by just adding&amp;nbsp;CONFIG_DEVICE_POWER_MANAGEMENT=y in prj.conf file gives error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The error is:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;Building ‘zephyr/libzephyr.a’ from solution ‘build’ in configuration ‘Common’
  Compiling ‘device.c’
    #error &amp;quot;Add SoC&amp;#39;s core devices list for PM&amp;quot;
    &amp;#39;MAX_PM_DEVICES&amp;#39; undeclared here (not in a function)
    &amp;#39;NUM_CORE_DEVICES&amp;#39; undeclared (first use in this function); did you mean &amp;#39;MAX_PM_DEVICES&amp;#39;?
    each undeclared identifier is reported only once for each function it appears in
    &amp;#39;core_devices&amp;#39; undeclared (first use in this function); did you mean &amp;#39;device&amp;#39;?
    
    &amp;#39;device_retval&amp;#39; defined but not used [-Wunused-variable]
    &amp;#39;device_ordered_list&amp;#39; defined but not used [-Wunused-variable]
  Compiling ‘nrf_power_clock.c’
  Compiling ‘sys_clock_init.c’
  Compiling ‘nrf_rtc_timer.c’
  Compiling ‘secure_services_ns.c’
Build failed&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tried to compile this example also:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/master/samples/subsys/power/device_pm/src"&gt;https://github.com/nrfconnect/sdk-zephyr/tree/master/samples/subsys/power/device_pm/src&lt;/a&gt;, but it gives the same error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How to remove this error? Do I need to add anything else in prj.conf file?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/258763?ContentTypeID=1</link><pubDate>Tue, 07 Jul 2020 09:31:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1be1eeb7-d17d-443f-aa25-b1a6cf05ce45</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for the explaination.&lt;/p&gt;
&lt;p&gt;I tried the 2nd option.&lt;/p&gt;
&lt;p&gt;I am able to disable SPIM3 but I don&amp;#39;t understand how to re-enable it.&lt;/p&gt;
&lt;p&gt;The code is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CS_pin    13
#define MISO_pin  12
#define MOSI_pin  11

void disable_spi()
{
    NRF_SPIM3_NS-&amp;gt;TASKS_STOP = 1;
    NRF_SPIM3_NS-&amp;gt;ENABLE = 0;      // To disable SPI3
    NRF_SPIM3_NS-&amp;gt;PSEL.SCK = 0xFFFFFFFF;
    NRF_SPIM3_NS-&amp;gt;PSEL.MISO = 0xFFFFFFFF;
    NRF_SPIM3_NS-&amp;gt;PSEL.MOSI = 0xFFFFFFFF;
    NRF_P0_NS-&amp;gt;OUTCLR = (1 &amp;lt;&amp;lt; CS_pin);
    NRF_P0_NS-&amp;gt;OUTCLR = (1 &amp;lt;&amp;lt; MISO_pin);
    NRF_P0_NS-&amp;gt;OUTCLR = (1 &amp;lt;&amp;lt; MOSI_pin);
}

void enable_spi()
{
    NRF_SPIM3_NS-&amp;gt;ENABLE = 7;     // To enable SPI3
//    NRF_P0_NS-&amp;gt;OUTSET = 0xFFFFFFFF;
//    NRF_SPIM3_NS-&amp;gt;INTENSET = (1 &amp;lt;&amp;lt; MISO_pin);
//    NRF_SPIM3_NS-&amp;gt;INTENSET = (1 &amp;lt;&amp;lt; MOSI_pin);
    NRF_SPIM3_NS-&amp;gt;TASKS_START = 1;
}

void main(){
	while (1) {

              if(sdcard)
              {

                  sd_card();
                  file_open();
                  printk(&amp;quot;Disabling SPIM3\n&amp;quot;);
                  disable_spi();
                  printk(&amp;quot;Disabled SPIM3\n&amp;quot;);
                  enable_spi();
                  file_open();
                  sdcard = 0;
              }
		k_sleep(1000);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With the above code, SPIM3 is disabled and all pins goes low.&lt;/p&gt;
&lt;p&gt;1. Is this the correct way to disable SPI or anything else is needed?&lt;/p&gt;
&lt;p&gt;2. To enable, the value is 7 or 8?&lt;/p&gt;
&lt;p&gt;For UART, I saw it is 8. But here&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fspim.html&amp;amp;cp=2_0_0_5_12"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fspim.html&amp;amp;cp=2_0_0_5_12&lt;/a&gt;, it shows 7 for SPIM. The Enable registers for both UART and SPIM is same. So which value is correct for SPIM?&lt;/p&gt;
&lt;p&gt;When I tried with&amp;nbsp;NRF_SPIM3_NS-&amp;gt;ENABLE = 8;&lt;/p&gt;
&lt;p&gt;MISO and MOSI goes high but CS pin is still low.&lt;/p&gt;
&lt;p&gt;When I tried with&amp;nbsp;NRF_SPIM3_NS-&amp;gt;ENABLE = 7;&lt;/p&gt;
&lt;p&gt;CS pin goes high but MISO and MOSI are still low and I get the file open error (-5) which is I/O error.&lt;/p&gt;
&lt;p&gt;So which value is correct for Enable register and how does all SPI pin levels goes high again?&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Jagruti&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/256990?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 15:21:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b45d0569-f4a9-43d8-a361-e9ad20aece12</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Jagruti_N2A"]Could you please tell in detail? How to use&amp;nbsp;&lt;span&gt;CONFIG_DEVICE_POWER_MANAGEMENT in the application or use the uninit function to disable and again re-enable the SPI?&lt;/span&gt;[/quote]
&lt;p&gt;Implementing DEVICE_POWER_MANAGEMENT requires more development, as shown in this example:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/master/samples/subsys/power/device_pm/src"&gt;https://github.com/nrfconnect/sdk-zephyr/tree/master/samples/subsys/power/device_pm/src&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you do not want to implement the above device power management scheme, you can write to the NRF_SPIM3 registers directly to disable it, then write to the GPIOs to set them in default position again. By including &amp;quot;&lt;span&gt;#&lt;/span&gt;&lt;span&gt;include&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;hal/nrf_gpio.h&lt;span&gt;&amp;gt;&amp;quot; in your project, you can almost copy-paste the nrf_gpio calls, you just have to map your pins to the one&amp;#39;s that is default set. The pin configuration should be seen in your overlay file.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Håkon&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/256858?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 09:49:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2d80ace-3cdc-46c9-80fb-65f49d51189f</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for the solutions.&lt;/p&gt;
&lt;p&gt;But I don&amp;#39;t understand how to implement it.&lt;/p&gt;
&lt;p&gt;Could you please tell in detail? How to use&amp;nbsp;&lt;span&gt;CONFIG_DEVICE_POWER_MANAGEMENT in the application or use the uninit function to disable and again re-enable the SPI?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you in advance.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/255574?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 13:43:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6f6cc7d-27b9-48ff-a23f-f1976441759f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The _uninit function essentially disables the callback, turns off the SPIM module, and sets all pins to their default configuration. But, what it also does is to disable the callback function and interrupts, which can be a bit hard to re-enable again.&lt;/p&gt;
&lt;p&gt;I would rather recommend either mimic&amp;#39;ing the uninit function by writing directly to the NRF_SPIM3 registers (and re-doing this when you want to re-enable the SPIM), or look into the power saving module (&lt;span&gt;CONFIG_DEVICE_POWER_MANAGEMENT=y)&lt;/span&gt;, which is supported by the SPIM module:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spim.c#L322-L367"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spim.c#L322-L367&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/255444?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 09:06:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5078a342-d4b5-4d0e-9e00-bc6bcea14894</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I am able to uninitialize the SPI3 using&amp;nbsp;nrfx_spim_uninit() function.&lt;/p&gt;
&lt;p&gt;Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	while (1) {

              if(sdcard)
              {

                  sd_card();
                  file_open();      // To open and read the file
                  printk(&amp;quot;SPI uninitialized\n&amp;quot;);
                  nrfx_spim_uninit(DT_INST_0_ZEPHYR_MMC_SPI_SLOT_BUS_NAME);   // To uninitialize the SPI
                  sdcard = 0;
              }
		k_sleep(1000);
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But how can I initialize same SPI peripheral again?&lt;/p&gt;
&lt;p&gt;Now on button press, the SPI is initializing. After reading the file, I am disabling the SPI. But again if I press the button, SPI should initialize or not?&lt;/p&gt;
&lt;p&gt;In sd_card() function, disk and spi initialization is present.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void sd_card()
{
        static const char *disk_pdrv = &amp;quot;SD&amp;quot;;
		u64_t memory_size_mb;
		u32_t block_count;
		u32_t block_size;

		if (disk_access_init(disk_pdrv) != 0) {
			LOG_ERR(&amp;quot;Storage init ERROR!&amp;quot;);
		}

		if (disk_access_ioctl(disk_pdrv,
				DISK_IOCTL_GET_SECTOR_COUNT, &amp;amp;block_count)) {
			LOG_ERR(&amp;quot;Unable to get sector count&amp;quot;);

		}
		LOG_INF(&amp;quot;Block count %u&amp;quot;, block_count);

		if (disk_access_ioctl(disk_pdrv,
				DISK_IOCTL_GET_SECTOR_SIZE, &amp;amp;block_size)) {
			LOG_ERR(&amp;quot;Unable to get sector size&amp;quot;);
		}
		printk(&amp;quot;Sector size %u\n&amp;quot;, block_size);

		memory_size_mb = (u64_t)block_count * block_size;
		printk(&amp;quot;Memory Size(MB) %u\n&amp;quot;, (u32_t)memory_size_mb&amp;gt;&amp;gt;20);

	mp.mnt_point = FATFS_MNTP;

	int res = fs_mount(&amp;amp;mp);

	if (res == FR_OK) {
		printk(&amp;quot;Disk mounted.\n&amp;quot;);
		lsdir(FATFS_MNTP);

	} else {
		printk(&amp;quot;Error mounting disk.\n&amp;quot;);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So is it possible to initialize spi, disk and repeat the open and read operation on file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/254684?ContentTypeID=1</link><pubDate>Fri, 12 Jun 2020 11:04:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f3394e3-3f4e-4cf4-b702-b4e5d048aea9</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="Jagruti_N2A"]I will try to disable SPIM by manually writing&amp;nbsp;&lt;span&gt;NRF_SPIM3 registers. If I encounter any problem, I will ask again. Thank you in advance.&lt;/span&gt;[/quote]
&lt;p&gt;No worries! contact me if you&amp;#39;re stuck.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/254552?ContentTypeID=1</link><pubDate>Thu, 11 Jun 2020 15:21:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c70a30b8-696f-409d-bfd7-55bd50c0449e</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for the reply.&lt;/p&gt;
&lt;p&gt;I am not using all the SPI instances. I am aware that the same base address is shared by the peripherals. So I am using UART0, UART1, I2C2 and SPI3.&lt;/p&gt;
&lt;p&gt;I will try to disable SPIM by manually writing&amp;nbsp;&lt;span&gt;NRF_SPIM3 registers. If I encounter any problem, I will ask again. Thank you in advance.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to disable/uninitialize SPI on nRF9160DK used for interfacing SD card?</title><link>https://devzone.nordicsemi.com/thread/254225?ContentTypeID=1</link><pubDate>Wed, 10 Jun 2020 11:03:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19358ea1-8fbe-49ed-8c51-da71cb0fe8c0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you using all SPI instances (note: some devices are shared, look for devices that has the same base address here:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/memory.html?cp=2_0_0_3_1_1#topic"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf9160/memory.html?cp=2_0_0_3_1_1#topic&lt;/a&gt;) ?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The zephyr SPI driver does not have functionality to uninit:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/spi.h"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/spi.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, in order to disable the SPIM in use, you have to manually write to the NRF_SPIMx (where &amp;#39;x&amp;#39; is the peripheral you use) registers. The nrfx driver has a function for un-initing:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-hal_nordic/blob/master/nrfx/drivers/src/nrfx_spim.c#L430"&gt;https://github.com/nrfconnect/sdk-hal_nordic/blob/master/nrfx/drivers/src/nrfx_spim.c#L430&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>