This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC2640R2: CC2640R2F SPI Driver Behavior

Part Number: LAUNCHXL-CC2640R2

I’m looking at how the SPI driver behaves on the CC2640R2, specifically with how the Chip Select (CS) pin functions. It looks like the device is capable of controlling the CS via hardware, as well as allowing the application to control via software. I was reading through the SPI.h file and saw the following excerpt and wanted to confirm some questions I have.

* <h2><a NAME="Master_Slave_Modes">Master/Slave Modes</a></h2>
* This SPI driver functions in both SPI master and SPI slave modes.
* Logically, the implementation is identical, however the difference between
* these two modes is driven by hardware. As a SPI master, the peripheral is
* in control of the clock signal and therefore will commence communications
* to the SPI slave immediately. As a SPI slave, the SPI driver prepares
* the peripheral to transmit and receive data in a way such that the
* peripheral is ready to transfer data when the SPI master initiates a
* transaction.
*
* ### Asserting on Chip Select
* The SPI protocol requires that the SPI master asserts a SPI slave's chip
* select pin prior to starting a SPI transaction. While this protocol is
* generally followed, various types of SPI peripherals have different
* timing requirements as to when and for how long the chip select pin must
* remain asserted for a SPI transaction.
*
* Commonly, the SPI master uses a hardware chip select to assert and
* de-assert the SPI slave for every data frame. In other cases, a SPI slave
* imposes the requirement of asserting the chip select over several SPI
* data frames. This is generally accomplished by using a regular,
* general-purpose output pin. Due to the complexity of such SPI peripheral
* implementations, this SPI driver has been designed to operate
* transparently to the SPI chip select. When the hardware chip
* select is used, the peripheral automatically selects/enables the
* peripheral. When using a software chip select, the application needs to
* handle the proper chip select and pin configuration. Chip select support
* will vary per SPI peripheral, refer to the device specific implementation
* documentation for details on chip select support.
*
* - _Hardware chip select_ No additional action by the application is
* required.
* - _Software chip select_ The application needs to handle the chip select
* assertion and de-assertion for the proper SPI peripheral.

  • What is meant by “When the SPI master initiates a transaction” when the device is in SPI slave mode? Does initiates a transaction mean a CLK signal begins on the CLK line or does this involve the CS going low?
  • When the device is in SPI slave mode, what’s the behavior of the hardware chip select? Is there a chip select?
  • Does “this SPI driver has been designed to operate transparently to the SPI chips select” mean the CS line essentially ignored regardless if device is setup as SPI master or slave?
    • For example, in SPI slave mode, if a CLK signal is present on the CLK line, data would exit the Tx buffer/be read into the Rx buffer regardless of the CS? Or would it need to acknowledge CS being active low before data would enter/leave Tx/Rx buffers?
  • What’s the procedure for switching between hardware chip select and software chip select? Is it as simple as defining the CS pin to be PIN_UNASSIGNED to disable the hardware chip select?

  • Hi, let's see if we can put some answers to your questions:

    "What is meant by “When the SPI master initiates a transaction” when the device is in SPI slave mode? Does initiates a transaction mean a CLK signal begins on the CLK line or does this involve the CS going low?"

    - The SPI master initiates a transfer by pulling CS low (this is the easy answer, there are some variations on how the CS pin is used depending on the frame format, you can read about this in the technical reference manual).

    "When the device is in SPI slave mode, what’s the behavior of the hardware chip select? Is there a chip select?"

    - Yes, there is still a chip select. When in SPI slave mode, the CS is an input used to "select" the device on the SPI bus.

    "Does “this SPI driver has been designed to operate transparently to the SPI chips select” mean the CS line essentially ignored regardless if device is setup as SPI master or slave?

    For example, in SPI slave mode, if a CLK signal is present on the CLK line, data would exit the Tx buffer/be read into the Rx buffer regardless of the CS? Or would it need to acknowledge CS being active low before data would enter/leave Tx/Rx buffers?"

    - This is maybe a bit confusing. What it means is that as a Slave, the module itself will keep track of the CS state to know if it should transfer/receive data or not. It is nothing the user or driver need to know about (other then making sure the PIN mux is correct). So in your example, the slave would still require the CS to be asserted before it stars to clock anything out/in.

    As a Master, this means that the driver will not do anything different in terms of how it performs a transaction regardless of what type of CS you want to use.
    The only differens (driver wise) from using a Software CS vs a hardware CS is that in the SW case, the actual SPI modules CS is not muxed out to the physical pin and the user will be left to control the CS.

    "What’s the procedure for switching between hardware chip select and software chip select? Is it as simple as defining the CS pin to be PIN_UNASSIGNED to disable the hardware chip select?"

    - Yes, that is basically what you will have to do to disable the hardware CS.

    I hope this helped clear things up!

  • Hi M-W,

    Thank you for your detailed answers, that does clear this up significantly!

    One more question I neglected to ask that would explain all of these CS questions, how does the CS work with the NPI/SDI software with power savings enabled? As I step through NPI setup for SPI, it's set to be a SPI slave device, but I'm wondering how the CS pin is used here then given what you said above. I would have to assume the CS pin is tied to same pin as MRDY, so essentially MRDY also acts as the CS? Not only would MRDY wake up the CC2640R2 from sleep, but it would also enable SPI comms through the CS being active low. I'm looking through the host_test project, and the board file doesn't have any pins assigned for SPI1, so having some difficulty matching how these pins are used. I know host_test doesn't use power_saving, so may not be the best example to look at, is there a different example that uses NPI that would make the SPI implementation clearer?

    Thanks!
  • Hi,

    I do not know the details on how the NPI is setup and work and how the ble5 board files are setup. However, in the case CS is not routed out (like in the case where it it UNASSIGNED) it will be internally tied to "0". This would mean it would always be "selected" and accepting data.

  • Ah, interesting, that's valuable information. Is there anyone you can forward this question onto that would know how NPI is intended to be setup with regards to board pins using SPI in slave mode with power savings turned on?

    Thanks for all your help so far, very informative!
  • I would suggest you make another e2e post about this as it is a new subject, that will also make it easier for those with insight to pick it up :)
  • Ok will do, thanks for all your help!