SPI end of TX

Hi there,

We're using nRF52840, IAR 8.40.1, nRF5_SDK_16.0.0_98a08e2.

My question is, I need to toggle a GPIO pin right after SPI finishes the TX transaction and right before it starts the RX transaction.
Is it possible to do that?  If yes, where in the SDK can I intercept that?

For example, I notice that there's this event:
NRF_SPIM_EVENT_ENDTX

Is this the event where we just finished sending to MOSI and are about to receive from MISO?
If yes, is it possible to provide a callback when this event happens?

Thanks,
Cecylia

Parents Reply Children
  •   thanks! That sounds very much like what I'm looking for.

    I'm going to find more examples on how to set the DCX pin.  But, from quick browsing on the SDK, it looks like I will have to change the nrf_drv_spi_init() in the driver? Because during this SPI init, it will call SPIM init, but I don't see any code that sets 'dcx_pin'.

    Did you have to change the driver, too?

    ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
                                nrf_drv_spi_config_t const * p_config,
                                nrf_drv_spi_evt_handler_t    handler,
                                void *                       p_context)
    {
    ...
    
    #ifdef SPIM_PRESENT
            nrfx_spim_config_t config_spim = NRFX_SPIM_DEFAULT_CONFIG;
            config_spim.sck_pin        = p_config->sck_pin;
            config_spim.mosi_pin       = p_config->mosi_pin;
            config_spim.miso_pin       = p_config->miso_pin;
            config_spim.ss_pin         = p_config->ss_pin;
            config_spim.irq_priority   = p_config->irq_priority;
            config_spim.orc            = p_config->orc;
            
    // Where can we set the 'dcx_pin'??? Need to modify nrf_drv_spi_init??? 
    
            config_spim.frequency      = (nrf_spim_frequency_t)p_config->frequency;
            config_spim.mode           = (nrf_spim_mode_t)p_config->mode;
            config_spim.bit_order      = (nrf_spim_bit_order_t)p_config->bit_order;
            result = nrfx_spim_init(&p_instance->u.spim,
                                    &config_spim,
                                    handler ? spim_evt_handler : NULL,
                                    (void *)inst_idx);
    #endif

  • (NRFX_SPIM_EXTENDED_ENABLED needs to be set to enable the DCX stuff in nrfx_spim.h - DCX allows multiple lead bytes, probably what you are looking for. Common with some displays; may need later SDKs v17 on, not sure about SDK16 but you can copy the v17 stuff to v16, fairly straightforward.

  • Cool!  I saw nrfx_spim in the examples directory.  So I'm going to try that first.  Thanks so much  !! 

  • I ported the nrfx_spim driver from SDK 16's examples.  I could successfully toggled the GPIO pin.  Very nice!  

    I'm supposed to do this to 2 SPI, though.  And, this extended feature only works for one SPI - SPIM3.  I guess, I still need to figure out what to do with the other SPI. 

    This is very helpful, though.  Thank you very much  !

     any other suggestions? At least for the other SPI?

    Thanks,
    Cecylia


  • You're very welcome. If you can spare another pin and don't require simultaneous SPI to both devices maybe use 2 x /CS, one for each device, and change the .cs pin before each transfer. The other signals can all be common between the devices.

Related