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

SPI slave and Sofdevice

Hi.

Is it possible to use SPI slave and SofDevice at the same time? I try to do device which status will be read by master uc by SPI. I'm using nRF51422(rev.3), SDK10.0.0, SD5.0.1. ANT application working as 4-channel background scanning. I used SPI slave example (SDK example folder) and it's working fine (without softdevice). Background scanning also work, but without SPI slave.

Best regards PW

  • It should be possible to use SPI slave and SoftDevice together. What happens if you use SPI slave with the SoftDevice?

  • When SPI transmission occured, program stops on:

    spis_irq_handler(NRF_SPIS_Type * p_spis, spis_cb_t * p_cb)

    SPI transmission is slow: 250kbps

    Initialization SPI slave (before soft device init):

        static void spi_slave_event_handle(nrf_drv_spis_event_t event)
    {
        uint32_t err_code;
        
        if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
        {
    				err_code = sd_nvic_SetPriority(SPI1_TWI1_IRQn, NRF_APP_PRIORITY_LOW);       
    
    				APP_ERROR_CHECK_BOOL(event.rx_amount == RX_BUF_SIZE);
            
            bool success = spi_slave_buffer_check(m_rx_buf, event.rx_amount);
            APP_ERROR_CHECK_BOOL(success);
            
            err_code = nrf_drv_spis_buffers_set(&m_spis, m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_rx_buf));
            APP_ERROR_CHECK(err_code);          
        }
    }
    
        uint32_t spi_slave_init(void)
    {
        uint32_t              err_code;
        nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG(SPIS_INSTANCE_NUMBER); 
    
        spis_config.miso_pin        = ANT_MISO_PIN;
        spis_config.mosi_pin        = ANT_MOSI_PIN;
        spis_config.sck_pin         = ANT_SCK_PIN;
        spis_config.csn_pin         = ANT_CS_PIN;
        spis_config.mode            = NRF_DRV_SPIS_MODE_1;
        spis_config.bit_order       = NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST;
        spis_config.def             = DEF_CHARACTER;
        spis_config.orc             = ORC_CHARACTER;
        
        err_code = nrf_drv_spis_init(&m_spis, &spis_config, spi_slave_event_handle);
        APP_ERROR_CHECK(err_code);
        
        //Initialize buffers.
        spi_slave_buffers_init(m_tx_buf, m_rx_buf, (uint16_t)TX_BUF_SIZE);
        
        //Set buffers.
        err_code = nrf_drv_spis_buffers_set(&m_spis, m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_rx_buf));
        APP_ERROR_CHECK(err_code);            
    
        return NRF_SUCCESS;
    }
    

    Have you got any example with working softdevice?

    PW

  • It stops? Where in spis_irq_handler() does it stop? Why are you calling err_code = sd_nvic_SetPriority(SPI1_TWI1_IRQn, NRF_APP_PRIORITY_LOW); every time you get the NRF_DRV_SPIS_XFER_DONE event? And why do you not check the returned error code?

  • sd_nvic_SetPriority(SPI1_TWI1_IRQn, NRF_APP_PRIORITY_LOW) - my mistake, I erased it, but it didn't help. I always get NRF_DRV_SPIS_XFER_DONE event after master transfer, but after SPI trasmission I never get again ant_evt_dispatch(ant_evt_t * p_ant_evt).

  • Ok. Maybe you can edit your question and include your complete project? So I can test it here?

Related