Just to be sure about connecting a W25X40CLSNIG
-
While reading about the W25X40CLSNIG I noticed they make use of an SPI connection using pin D11 (MOSI), D12 (MISO) and D13 (SCK) on the Arduino. Just like the nRF24L modules do.
So, I also did some reading on SPI and I found out that the beauty of SPI is that devices can share these pins.
Did I read and interpret this correct?
Is there a snag that I need to know about?I found these libs for using the W25X40CLSNIG https://github.com/LowPowerLab/SPIFlash.git.
I found these datasheets: http://www.winbond.com/NR/rdonlyres/EE30B34B-8D95-4519-84F4-428F2515F06D/0/SerialFlashSelectionGuide1112911.pdf
I found this schematic for the Moteino: MoteinoR4_schematic.pdf
I found this schematic on flashrom: http://flashrom.org/File:Uno_BIOS_Flasher_2.png
-
@marceltrapman devices share the miso/mosi/sck pins but each device needs a separate select (cs) pin to indicates it's being addressed. This can be a regular gpio output pin.
The nrf24 also requires a ce pin, but this is not spi standard.
-
@Yveaux Thanks, that means I am doing things the correct way
-
Yes, more than one SPI device can share the MISO, MOSI, and Clock pins!
The caution is that there are different modes for SPI, and different speeds. If two devices (or their unmodified libraries) use different modes or speeds, then you have to be careful to use the right setup for SPI each time you use one of the devices.
One approach is for each transaction with a given device to set up the SPI the way it needs it (ie: not to assume that the original initialization will "stick") - that protects you against other libarires. By "transaction" I just mean a set of SPI transfers with one device which will be done atomically, without any intervening access to another SPI device.
Or there's the polite approach - when beginning a transaction, you can save the old SPI setup and restore it when you are done.
So if two device libraries don't seem to share the same SPI service well, that gives you something to check.
Where it gets trickier is if any device uses SPI in an interrupt. What if the interrupt happens in the middle of the other device's transactions? You have to pay attention to disabling interrupts (globally or for SPI) and respecting state even more carefully.
If SPI is not being accessed via interrupts, sharing devices may work out of the box, or you might need to tweak things. But sharing is very feasible and often done (with different chip selects of course, as has been noted).
-
This is work in progress: http://www.dorkbotpdx.org/blog/paul/spi_transactions_in_arduino