Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK 15. SPI driver sttting with ss_pin NRF_DRV_SPI_PIN_NOT_USED

Hi All!

I use SPI with ss_pin = NRF_DRV_SPI_PIN_NOT_USED. but seems it doesn not work properly.

in the file nrfx_spi.c , the following code exist to init ss_pin during initialization :

    if (p_config->ss_pin != NRFX_SPIM_PIN_NOT_USED)
    {
        if (p_config->ss_active_high)
        {
            nrf_gpio_pin_clear(p_config->ss_pin);
        }
        else
        {
            nrf_gpio_pin_set(p_config->ss_pin);
        }
        nrf_gpio_cfg_output(p_config->ss_pin);
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
        if (p_config->use_hw_ss)
        {
            m_cb[p_instance->drv_inst_idx].use_hw_ss = p_config->use_hw_ss;
            nrf_spim_csn_configure(p_spim,
                                   p_config->ss_pin,
                                   (p_config->ss_active_high == true ?
                                        NRF_SPIM_CSN_POL_HIGH : NRF_SPIM_CSN_POL_LOW),
                                   p_config->ss_duration);
        }
#endif
        m_cb[p_instance->drv_inst_idx].ss_pin = p_config->ss_pin;
        m_cb[p_instance->drv_inst_idx].ss_active_high = p_config->ss_active_high;
    }

according to this CODE , If ss_pin == NRFX_SPIM_PIN_NOT_USED , m_cb[p_instance->drv_inst_idx].ss_pin] remains ZERO (uninit) and then, in the function  nrfx_spim_xfer(...) , the CODE:

    if (p_cb->ss_pin != NRFX_SPIM_PIN_NOT_USED)
    {
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
        if (!p_cb->use_hw_ss)
#endif
        {
            if (p_cb->ss_active_high)
            {
                nrf_gpio_pin_set(p_cb->ss_pin);
            }
            else
            {
                nrf_gpio_pin_clear(p_cb->ss_pin);
            }
        }
    }

will always be executed with wrong ss_pin value (zero ?).

Please, explain this behavior.

thanks.

  • Aylik,

    I think you are right. This seems like a bug, They missed to add the else statement for ss_pin

     

    You can very easily fix this by adding the missing else statement for the ss_pin.

     

        if (p_config->ss_pin != NRFX_SPIM_PIN_NOT_USED)
        {
            if (p_config->ss_active_high)
            {
                nrf_gpio_pin_clear(p_config->ss_pin);
            }
            else
            {
                nrf_gpio_pin_set(p_config->ss_pin);
            }
            nrf_gpio_cfg_output(p_config->ss_pin);
    #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
            if (p_config->use_hw_ss)
            {
                m_cb[p_instance->drv_inst_idx].use_hw_ss = p_config->use_hw_ss;
                nrf_spim_csn_configure(p_spim,
                                       p_config->ss_pin,
                                       (p_config->ss_active_high == true ?
                                            NRF_SPIM_CSN_POL_HIGH : NRF_SPIM_CSN_POL_LOW),
                                       p_config->ss_duration);
            }
    #endif
            m_cb[p_instance->drv_inst_idx].ss_pin = p_config->ss_pin;
            m_cb[p_instance->drv_inst_idx].ss_active_high = p_config->ss_active_high;
        }
    else
        {
             m_cb[p_instance->drv_inst_idx].ss_pin = NRF_SPIM_PIN_NOT_CONNECTED; // Please check the spelling
        }

  • What version of the SDK are you using? I have nRF5_SDK_15.0.0_a53641a, and my nrfx_spi.c doesn't have a lot of that structure, pretty much everything below "#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)"

    Thanks,

    -Ben

Related