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

m_nrf_spi_mngr

I have two SPI ports, each connected to multiple SPI devices. Can I apply for two m_nrf_spi_mngr at the same time? (NRF_SPI_MNGR_DEF(m_nrf_spi_mngr, SPI1_QUEUE_LENGTH, SPI1_INSTANCE_ID)), is there any special need to pay attention to using two m_nrf_spi_mngr at the same time? I use two, one has always failed, can't receive data

Parents
  • Are you using two different SPI instances?

    Do you mind sharing the relevant code?

  • yes,use two different SPI instances.not sharing the relevant code

  • Then do you have any debug information on the SPI issue?

  • I found that every time I stuck in the following code "while (p_cb->internal_transaction_in_progress)", the CS signal has been pulled low, but no other signal (SPI0 or SPI1, DMA is on)

    ret_code_t nrf_spi_mngr_perform(nrf_spi_mngr_t const *          p_nrf_spi_mngr,
                                    nrf_spi_mngr_transfer_t const * p_transfers,
                                    uint8_t                         number_of_transfers,
                                    void (* user_function)(void))
    {
        ASSERT(p_nrf_spi_mngr != NULL);
        ASSERT(p_transfers != NULL);
        ASSERT(number_of_transfers != 0);
    
        ret_code_t err_code = NRF_SUCCESS;
        nrf_spi_mngr_cb_t * p_cb = p_nrf_spi_mngr->p_nrf_spi_mngr_cb;
    
        CRITICAL_REGION_ENTER();
        if (p_cb->internal_transaction_in_progress)
        {
            err_code = NRF_ERROR_BUSY;
        }
        else
        {
            p_cb->internal_transaction_in_progress = true;
        }
        CRITICAL_REGION_EXIT();
    
        if (err_code != NRF_ERROR_BUSY)
        {
            nrf_spi_mngr_transaction_t internal_transaction =
            {
                .begin_callback      = NULL,
                .end_callback        = spi_internal_transaction_cb,
                .p_user_data         = (void *)p_nrf_spi_mngr,
                .p_transfers         = p_transfers,
                .number_of_transfers = number_of_transfers,
            };
    
            err_code = nrf_spi_mngr_schedule(p_nrf_spi_mngr, &internal_transaction);
    
            if (err_code == NRF_SUCCESS)
            {
                while (p_cb->internal_transaction_in_progress)
                {
                    if (user_function)
                    {
                        user_function();
                    }
                }
                err_code = p_cb->internal_transaction_result;
            }
        }
    
        return err_code;
    }

Reply
  • I found that every time I stuck in the following code "while (p_cb->internal_transaction_in_progress)", the CS signal has been pulled low, but no other signal (SPI0 or SPI1, DMA is on)

    ret_code_t nrf_spi_mngr_perform(nrf_spi_mngr_t const *          p_nrf_spi_mngr,
                                    nrf_spi_mngr_transfer_t const * p_transfers,
                                    uint8_t                         number_of_transfers,
                                    void (* user_function)(void))
    {
        ASSERT(p_nrf_spi_mngr != NULL);
        ASSERT(p_transfers != NULL);
        ASSERT(number_of_transfers != 0);
    
        ret_code_t err_code = NRF_SUCCESS;
        nrf_spi_mngr_cb_t * p_cb = p_nrf_spi_mngr->p_nrf_spi_mngr_cb;
    
        CRITICAL_REGION_ENTER();
        if (p_cb->internal_transaction_in_progress)
        {
            err_code = NRF_ERROR_BUSY;
        }
        else
        {
            p_cb->internal_transaction_in_progress = true;
        }
        CRITICAL_REGION_EXIT();
    
        if (err_code != NRF_ERROR_BUSY)
        {
            nrf_spi_mngr_transaction_t internal_transaction =
            {
                .begin_callback      = NULL,
                .end_callback        = spi_internal_transaction_cb,
                .p_user_data         = (void *)p_nrf_spi_mngr,
                .p_transfers         = p_transfers,
                .number_of_transfers = number_of_transfers,
            };
    
            err_code = nrf_spi_mngr_schedule(p_nrf_spi_mngr, &internal_transaction);
    
            if (err_code == NRF_SUCCESS)
            {
                while (p_cb->internal_transaction_in_progress)
                {
                    if (user_function)
                    {
                        user_function();
                    }
                }
                err_code = p_cb->internal_transaction_result;
            }
        }
    
        return err_code;
    }

Children
Related