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

Need three SPI master interfaces

I am trying to use the sdk_config.h file from SDK15 to setup a custom board with a nRF52832.  The nRF5283 connects to three SPI peripherals.  For ease of software development the three SPI peripherals are all in slave mode, the nRF52 is master of all of them.

How do I assign pins in the sdk_config.h file? 

I have the feeling I am missing some important piece of documentation.  The only documentation I have found is the datasheet for the nRF52831 and the documentation directory of the SDK.

Parents
  • You cannot configure this within sdk_config.h

    Your best option is to configure at run-time, and reconfigure the SPIM at each time that you want to communicate with a selected SPI slave device

    nrfx_spim_config_t spim_config = NRFX_SPIM_DEFAULT_CONFIG;
    // Above sets default SPIM (SPI Master) configuration settings, with NO SPI pin assignments
    spim_config.ss_pin = your slave select pin (1 of your 3 choices);
    spim_config.miso_pin = your miso pin;
    spim_config.mosi_pin = your mosi pin;
    spim_config.sck_pin = your spi clock pin;
    spim_config.ss_active_high = false;
    
    // Initializes and enables spim ...
    err_code = nrfx_spim_init(&spim, &spim_config, spim_evt_handler, NULL);
    
    //... now proceed to do your SPI Master transfer to your selected SPI slave device
    // You would have to do a nrfx_spim_uninit() when you change SPI slave devices

    Also note, if each SPI slave supports different clock rates, data phases, etc ... then you would config differently at above configuration stage.

  • Why would I need to reconfigure the SPIM for each different device. 

    Aren't there three SPI controllers in the nRF52832: SPIM0 (ID 3), SPIM1 (ID 4), and SPIM2 (ID 35)?

  • Yes, that is correct, but important to know the limitations of that approach.

    = ===================================================

    From nRF52 User Manual ...

    15.2 Peripherals with shared ID
    In general, and with the exception of ID 0, peripherals sharing an ID and base address may not be used
    simultaneously. The user can only enable one at the time on this specific ID.

    = ===================================================

    ID 3 and 4 are common IDs between TWI and SPIM, so if your system is also using TWI, you may not be able to use all 3 the SPIM instances.

    = ===================================================

    In addition, each of your individual SPIM instances will (most likely) need to use unique pins for SPIM CLK, MISO, MOSI, SS-     

    It is my understanding that each SPIM instance software driver cannot share pins.  ... But I could be wrong here ... just haven't tried that.

    So with this approach, for 3 SPI slave devices, you may occupy up to 12 GPIO pins ... which may not be desirable, depending on the number of GPIOs available.

  • The board was designed with four pins dedicated to each SPI slave device.  There are now TWI/I2C devices on the board.  The main purpose of this board is to move data between the SPI ports and a device at the other end of the BLE link.

  • OK, so you will have to have some extra code to manage the TWI and SPI that are using the same peripheral ID.

    Depending on your use case, that may be a no-brainer, or there could be some run-time challenges.

    Otherwise ... good to go.

Reply Children
No Data
Related