<?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>Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave</link><description>Hello, 
 I am having a few issues with getting the SD card FATFS example code to share the same bus as another slave I transfer data to. 
 I have a few questions: 
 1) Since, I don&amp;#39;t need the two slaves to transfer simultaneously, should I have them use</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 Aug 2020 06:24:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave" /><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/263518?ContentTypeID=1</link><pubDate>Fri, 07 Aug 2020 06:24:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a39e2840-c9cc-40db-9d2a-ea944be53b05</guid><dc:creator>awneil</dc:creator><description>[quote userid="75667" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave/263506"]There&amp;#39;s nothing electrically to prevent this from working[/quote]
&lt;p&gt;Follow the links where I cited some reasons for avoiding this configuration. They are not electrical - they are to do with the way SD Cards communicate on the interface - in particular,&amp;nbsp;when an SD Card starts up, it is not in SPI mode.&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t say it can&amp;#39;t be done - just that there are issues to consider.&lt;/p&gt;
&lt;p&gt;An SD Card is not just another SPI Slave.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/263510?ContentTypeID=1</link><pubDate>Fri, 07 Aug 2020 01:30:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bdcb960-db8e-44b2-b938-123c5379db15</guid><dc:creator>wpaul</dc:creator><description>[quote userid="80584" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave/263486"]Hello, it&amp;#39;s been a year but I have tried all what you said. [/quote]
&lt;p&gt;I don&amp;#39;t believe it took you a whole year. It&amp;#39;s really rude to disappear for so long and then come back expecting more help. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
[quote userid="80584" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave/263486"]It won&amp;#39;t let me initialize FATfs blkdev without unitializing the SPI instance I have for the other slave I want to share the bus with.[/quote]
&lt;p&gt;It&amp;#39;s also really rude to only give a short sentence about your problem without giving any details or showing example code.&lt;/p&gt;
&lt;p&gt;Please note: the Nordic SDK probably contains its own diskio.c code to interface with FatFs. If it&amp;#39;s that code which is giving you trouble, then you may need to customize it. However I&amp;#39;m not going to do that for you.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/263506?ContentTypeID=1</link><pubDate>Fri, 07 Aug 2020 01:20:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82927ba2-7174-4d6f-8fc9-4469cfe004d6</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;This isn&amp;#39;t true. If you want to recommend that people avoid this configuration, do it for the right reason: it may be a little hard for newcomers. There&amp;#39;s nothing electrically to prevent this from working as long as you do it right.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve designed two boards where a single SPI controller instance was used with multiple slaves, including an SD card. The first design (NXP Kinetis KW01 chip) had three devices: an XPT2046 touch controller, ILI9341 display chip and an SD card all on the same SPI channel. With the nRF52840, I the design had just the SD card and XT2046 controller on the same SPI bus. Both designs worked fine.&lt;/p&gt;
&lt;p&gt;The things to remember are:&lt;/p&gt;
&lt;p&gt;- each slave uses the same SCK/MOSI/MISO pins, *but* each slave must be wired to its own chip select pin (as the hardware designer, you have to make sure this is true)&lt;/p&gt;
&lt;p&gt;- you have to be sure to only assert the chip select pin for one slave at a time when doing SPI transfers (assert CS1/do a transfer/release CS1, assert CS2/do a transfer/release CS2/etc...)&lt;/p&gt;
&lt;p&gt;- for each slave device, figure out what&amp;#39;s the fastest clock speed it can support, then see which one is the slowest -- set the SPI controller clock frequency so that it doesn&amp;#39;t exceed this slowest speed&lt;/p&gt;
&lt;p&gt;- if you&amp;#39;re using an RTOS (i.e. you have threads), use a mutex to guard access to the SPI controller (i.e. always take the mutex before doing a SPI transfer and then give the mutex after)&lt;/p&gt;
&lt;p&gt;Note that the rule about choosing the slowest clock speed can be fudged a little. With the nRF52840, I found you can actually change the FREQUENCY register on the fly without having to reinitialize everything. This may be necessary if the slowest slave&amp;#39;s max speed is so slow that using with the other slaves would result in them performing too poorly for your needs.&lt;/p&gt;
&lt;p&gt;That means you can switch the clock to low frequency only when you talk to the slow slave, and then switch it back to a higher frequency when you&amp;#39;re finished.&lt;/p&gt;
&lt;p&gt;Also, I&amp;#39;m not necessarily suggesting that people *should* share one SPI controller with many slaves, but I know that you *can* do it if necessary and it will work.&lt;/p&gt;
&lt;p&gt;I think the real complication here is figuring out how to make this work with the Nordic SDK in particular. For the boards I worked on, I did not use the Nordic SDK. (In fact I wrote my own driver for the nRF52 SPIM device.) I don&amp;#39;t know if there is a working example in the SDK that shows how to use a single SPI controller with two slaves. If there is, then that&amp;#39;s the model that should be followed here (and the fact that one slave ends up being an SD card shouldn&amp;#39;t really matter). If there isn&amp;#39;t such an example, then they really ought to add one since while it&amp;#39;s not a great idea, it&amp;#39;s not an especially rare use case either.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/263494?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 19:37:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de359f7a-4260-493c-ba92-c0610804a315</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;As I said early on in the thread:&lt;/p&gt;
[quote userid="6462" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave/202233"]In general (not specific to Nordic), I would always &lt;b&gt;try to avoid sharing an SD-Card with any other SPI device.&lt;/b&gt; I don&amp;#39;t really think that SD-Cards are designed to share their SPI interface [/quote]
&lt;p&gt;See:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/63517/interfacing-between-nrf52840-and-bme680-i2c-or-spi/258966#258966"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/63517/interfacing-between-nrf52840-and-bme680-i2c-or-spi/258966#258966&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/63570/adding-sd-card-as-second-spi-slave/259181#259181"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/63570/adding-sd-card-as-second-spi-slave/259181#259181&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/263486?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 16:12:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c242217-f353-4042-b67d-91b561279650</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;Hello, it&amp;#39;s been a year but I have tried all what you said. The main&amp;nbsp; problem seems to be the FatFs itself. It won&amp;#39;t let me initialize FATfs blkdev without unitializing the SPI instance I have for the other slave I want to share the bus with.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202701?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 21:41:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2afc1a13-6c82-408f-a10c-f25bd583818f</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;I just went to look at the documentation again, and I need to make one clarification/correction. The SPIM controller block in the nRF52840 has the hardware chip select feature, however I think you&amp;#39;re using the nRF52832 chip, and that one doesn&amp;#39;t have it. I forgot that you were using the nRF52832 when I was writing my previous reply. Sorry. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;However, note that when you call nrf_drv_spi_init(), you give it a pointer to an nrf_drv_spi_config_t structure. This structure has a member called ss_pin, where ss stands for Slave Select. This is also what I&amp;#39;m calling the chip select. While the nRF52832 doesn&amp;#39;t let you control the slave select pin from hardware, the Nordic SPI driver code can do it from software. When you set a pin value here, the nrfx_spi.c or nrfx_spim.c code will internally call nrf_gpio_pin_set() and nrf_gpio_pin_clear() to control the chip select pin when you issue a transfer.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s convenient if you only have one slave on the bus, but it doesn&amp;#39;t work if you have two. I think the reason you&amp;#39;re calling nrf_drv_spi_init() twice is that you&amp;#39;re not toggling the chip select pin yourself: you&amp;#39;re letting the Nordic SPI code do it for you via the ss_pin feature. So to go from one slave to the other, you have to keep re-initializing the SPI driver with a different ss_pin each time.&lt;/p&gt;
&lt;p&gt;What I think you need to do is set the ss_pin value to NRF_DRV_SPI_PIN_NOT_USED. Then you can initialize the SPI controller just once. After that, you need to modify your code to add explicit calls to nrf_gpio_pin_clear() (assert the chip select) and nrf_gpio_pin_set() (deassert the chip select) into your code before and after you issue SPI transactions to the slaves.&lt;/p&gt;
&lt;p&gt;In other words, you have to do this yourself instead of relying on the Nordic SPI code doing it for you.&lt;/p&gt;
&lt;p&gt;Note that I&amp;#39;m not using the nRF SDK for my project: I&amp;#39;m running an RTOS called ChibiOS and it has its own drivers for the SPIM block in the nRF52 chips. Conceptually though, it works the same. Really all I&amp;#39;m doing is initializing the SPIM block once, which configures the pin select registers (i.e. sets which pins are MOSI, MISO and SCK) and programs in the desired bus clock speed.&lt;/p&gt;
&lt;p&gt;Once the SPI bus itself is initialized, then I have to initiate SPI transfers from the different blocks that need to talk to the SPI peripherals. For the touch controller, I basically do:&lt;/p&gt;
&lt;p&gt;- assert CS pin for touch controller&lt;/p&gt;
&lt;p&gt;- issue SPI command to read the touch state&lt;/p&gt;
&lt;p&gt;- deassert CS pin for touch controller&lt;/p&gt;
&lt;p&gt;(The touch controller is very simple.)&lt;/p&gt;
&lt;p&gt;I also have an SD card driver module sitting under FatFs. When FatFs needs to read a block, it calls the block read function in the SD card driver, which behaves similarly:&lt;/p&gt;
&lt;p&gt;- assert CS pin for SD card&lt;/p&gt;
&lt;p&gt;- issue commands to read a sector from the card (involves several SPI bus transactions)&lt;/p&gt;
&lt;p&gt;- deassert CS pin for SD card&lt;/p&gt;
&lt;p&gt;What&amp;#39;s important here is to never have the CS pins for both the SD card and touch controller asserted at the same time. As I said earlier, I use a mutex to guard the bus, and both the touch controller code and SD card code have to acquire the mutex before they can do any SPI transfers. Since only one of them can acquire the mutex at a time, it stops them from both trying to talk to the SPI bus at once.&lt;/p&gt;
&lt;p&gt;I hope that makes sense.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202695?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 19:40:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9409dbe8-a6d5-415b-963c-b816c3412e8d</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;Also, are you doing an nrf_drv_spi_init for your touch controller as well as a blk_dev_init for your SD card on the same instance? Or do you only do it once for both?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202694?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 19:39:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df469b9c-2609-43bf-9aee-327b34f2e98f</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;How do I disable automatic CS handling? Do I give config a null Chipselect pin when initializing SPI?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202693?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 19:20:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:705eabfe-3d2b-4df5-ae32-a526b04d98ef</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;I know that the Nordic SPI controller has a feature where you can tell it what chip select pin to use and it will toggle it automatically when issuing transfers. Are you using this feature?&lt;/p&gt;
&lt;p&gt;Having the SPI controller assert the chip select line automatically is handy in that it saves you from having to manually toggle the GPIO pin yourself (there&amp;#39;s some savings in code), however it really only works well if there is one slave, because the SPI controller can only control one chip select pin at a time, and each slave has a different chip select line.&lt;/p&gt;
&lt;p&gt;If you are using the automatic chip select handling feature, then I could see how you&amp;#39;d have to reconfigure the SPI controller each time you decide to switch from using one slave to another. In that case, I would suggest that you stop doing it that way and manually toggle the chip select lines instead.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re not using that feature, then I&amp;#39;m not sure what could be wrong. For my current project I have an SD card and resistive touch controller on the same bus, and I can access both of them without needing to reconfigure the SPI bus in between. I do manually toggle the chip selects though.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202688?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 18:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:549ac169-356c-496d-a090-d14ad0588a2d</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;So I can get it to work if I uninitialize SPI in between SD card SPI transfers and other slave SPI transfers. Since it works I&amp;#39;ll move forward with this but if someone has an idea why I have to do this let me know so that I can optimize this further.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202670?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 14:54:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6fb09da9-3386-4b59-9afd-b31124be3d82</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for not being clear. Channel 2 is SCLK, Channel 3 is MOSI, Channel 4 is MISO, Channel 6 is CS of SD card and channel 7 is CS of another SPI slave that isn&amp;#39;t an SD card.&lt;/p&gt;
&lt;p&gt;Basically, I&amp;#39;m at a point where the custom board has already been fabricated and I have only allocated enough space for one SPI bus. Therefore, I will try my best on this revision to make this work with one bus if possible.&lt;/p&gt;
&lt;p&gt;I am currently not using an RTOS as we have deemed it not that useful right now since all the operations the device will be doing is very low frequency (0.5-10Hz) and they are not that complex.&lt;/p&gt;
&lt;p&gt;I think for now I will use some sort of flag/mutex within the callback functions for both the SPI slave and the SPI Fatfs drivers to prevent simultaneous communication. I&amp;#39;ll let you guys know what happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202668?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2019 14:45:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6da91549-3c07-412b-975a-66c4f4de7f7c</guid><dc:creator>jgvillap</dc:creator><description>&lt;p&gt;Damn, I didn&amp;#39;t know that SD-cards were designed to have its own SPI bus. It&amp;#39;s kind of too late now though since my custom board has space for only one bus. I will take note of that for future revisions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202234?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 22:25:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:833409b1-6c73-4367-b5b2-e4ee4e30f0b9</guid><dc:creator>wpaul</dc:creator><description>[quote userid="80584" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave"]1) Since, I don&amp;#39;t need the two slaves to transfer simultaneously, should I have them use the same SPI instance?[/quote]
&lt;p&gt;Usually it&amp;#39;s more a matter of how may pins you have available on the chip. The nRF52832 has 32 pins and multiple serial device blocks that can be enabled simultaneously. I don&amp;#39;t know how many you&amp;#39;re going to use for your application, but if you have enough, putting each device on its own dedicated bus avoids contention.&lt;/p&gt;
&lt;p&gt;I did build a project once where for various and sundry reasons I was forced to put 3 slaves on one bus -- sd card, graphics display and resistive touch controller chip. I used an RTOS, and to keep things from exploding, I used a mutex to guard access to the SPI controller. (Any time I needed to do a SPI transfer to one of the slaves, I had to acquire the mutex first, do the transfer, then release the mutex again after.)&lt;/p&gt;
&lt;p&gt;I think the Nordic SDK examples are mostly single-threaded. That being the case, you may be able to get away without using mutexes, provided you manage your chip selects correctly and don&amp;#39;t try to issue a transfer for slave B while a transfer for slave A is still in progress,&lt;/p&gt;
[quote userid="80584" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave"]3) Right now I am stuck where I write to SD card using sd_write() (Channel 6),[/quote]
&lt;p&gt;I know this might make sense to you, but remember the &amp;quot;we can&amp;#39;t see over your shoulder&amp;quot; rule. Tell us which channel is MISO, which is MOSI, which is SCK and which is CS.&lt;/p&gt;
&lt;p&gt;Each slave should have its own chip select pin. When a slave&amp;#39;s CS pin is asserted (pulled low), the it will listen to the MOSI/MISO/SCK pins on the SPI bus. If you&amp;#39;re sharing a bus with multiple slaves, only one slave must have its CS pin asserted at any given time.&lt;/p&gt;
[quote userid="6462" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave/202233"]I don&amp;#39;t know if the FatFs design assumes that it has exclusive control of the SPI lines.[/quote]
&lt;p&gt;Well, if you do use an RTOS, there are two things to worry about:&lt;/p&gt;
&lt;p&gt;- The SPI bus controller state&lt;/p&gt;
&lt;p&gt;- The FatFs library&amp;#39;s internal state&lt;/p&gt;
&lt;p&gt;FatFs has the notion of a synchronization object, and it has an optional API called ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant(). I think you need to define FF_FS_REENTRANT in order to use it. It&amp;#39;s up to you provide implementations of these functions that make sense for your application.&lt;/p&gt;
&lt;p&gt;If you have two threads in your RTOS which may both be accessing files via FatFs and they could be running concurrently, then you need to use the above mechanism to make sure FatFs itself stays sane.&lt;/p&gt;
&lt;p&gt;However, if you&amp;#39;re using SPI for your SD card, and you have another kind of SPI slave on the same bus (temperature sensor, display, etc...), then since that slave isn&amp;#39;t using FatFs, the above synchronization mechanism won&amp;#39;t help you. (The thread accessing files via FatFs will be using it, the thread talking to the other slave will not.)&lt;/p&gt;
&lt;p&gt;In that case, you need to define a mutex to guard the SPI bus itself, and then make sure both the FatFs SPI driver and your other slave code both use it, so that both can&amp;#39;t try to use the SPI bus at the same time.&lt;/p&gt;
&lt;p&gt;This means that when you use FatFs to access files, you&amp;#39;ll be taking two mutexes instead of one, but that&amp;#39;s ok (as long as FatFs always takes the SPI mutex _after_ its own mutex).&lt;/p&gt;
&lt;p&gt;To make a long story short, if you can spare the pins, it may be easier if you use two separate SPI buses.&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sharing a SPI bus with an SD card (FATFS) and another SPI Slave</title><link>https://devzone.nordicsemi.com/thread/202233?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 21:33:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d147ccef-899d-45c5-aa06-b7bcbcc723f5</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;In general (not specific to Nordic), I would always try to avoid sharing an SD-Card with any other SPI device.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t really that SD-Cards are designed to share their SPI interface.&lt;/p&gt;
[quote userid="80584" url="~/f/nordic-q-a/50584/sharing-a-spi-bus-with-an-sd-card-fatfs-and-another-spi-slave"]What part of the FATFS example needs to be done only once?[/quote]
&lt;p&gt;I don&amp;#39;t know if the FatFs design assumes that it has exclusive control of the SPI lines.&lt;/p&gt;
&lt;p&gt;You&amp;#39;d probably have to check that with ChaN:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elm-chan.org/fsw/ff/00index_e.html"&gt;http://elm-chan.org/fsw/ff/00index_e.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elm-chan.org/fsw/ff/bd/"&gt;http://elm-chan.org/fsw/ff/bd/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>