This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI protocol configuration. How to change spi0(master) into spis0(slave) in running time?

Hi all

I use nRf52840 with SDK 15.0. It allows  SPI SPIS and TWI (i2c) ,but almost 3 items in the same time. I want to use spi0 as master to configurate my other mcu and change to spis 0 as a receiver to receive data from this mcu. but the macro can't change. If I define spi0 ,I can't use spis0 anymore.  How to implement my requirement ?

Parents
  • That does not sould like you understood SPI in the first place. SPI always transmits and receives at the same time - you will typically just throw away the data from the path you don't need.

    The clock signal defines which party is the master: The clock generator is called SPI master, the clock receiver is called the SPI slave. You don't want to mix roles.

  • I know SPI. I need a real time communication in my project. My mcu is the producer, bursts real time data and transmit to nrf52840. If I use 52840 as master. I need to try to read data all the time to keep real time. It's unreasonable.

  • So just use the NRF52 always as a slave. Problem solved.

    Make the other MCU pull its configuration data over SPI as the master.

    You will need a properly thought out protocol anyway, because of the restrictions in the NRF52 SPIS (<=255 data bytes, CS handling, etc).

Reply
  • So just use the NRF52 always as a slave. Problem solved.

    Make the other MCU pull its configuration data over SPI as the master.

    You will need a properly thought out protocol anyway, because of the restrictions in the NRF52 SPIS (<=255 data bytes, CS handling, etc).

Children
  • 1. I need to download firmware to mcu with 52840 master before mcu work.

    2. I checked SDK code, and find that the data len is size_t (uint32) type in bottom code, so I changed the top code from uint8 to size_t . Now I can transmit size_t length data max in one time.

  • If I can't change SPI into SPIS in running time, I would write a simulation SPI master to download firmware to my mcu

  • You can change the pin configuration at runtime, and you can ENABLE and DISABLE peripherials.

    Not sure if NRF DRV functions work correctly in this case, I would just set those PSEL.XXX registers directly.

    I suggest using different instances (look at the base address in manual) for the master and the slave, this way you would only change the connect bit in the corresponding PSEL register.

  • thanks a lot. however I have used all the 3 SPI-TWI moudles, 1 i2c 2 spi-slave at runtime. I need one more spi master to configure 2 mcu. It seem that I have to write a simulate IO SPI-master.