SPIM3 configuration issues on nRF52840

Hi all,

I need to use the SPI3M interface and following various example I implemented the following code on the nRF52840 with SDK 3.0.2

  nrfx_err_t status;
        (void)status;

#if defined(__ZEPHYR__)
        IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM_INST_GET(SPIM_INST_IDX)), IRQ_PRIO_LOWEST,
                    NRFX_SPIM_INST_HANDLER_GET(SPIM_INST_IDX), 0, 0);
#endif

        PINCTRL_DT_DEFINE(SPI_NODE_RHS);

        nrfx_spim_config_t spim_config = NRFX_SPIM_DEFAULT_CONFIG(
            NRF_SPIM_PIN_NOT_CONNECTED,
            NRF_SPIM_PIN_NOT_CONNECTED,
            NRF_SPIM_PIN_NOT_CONNECTED,
            NRF_SPIM_PIN_NOT_CONNECTED);

        spim_config.frequency = MHZ(24);
        spim_config.mode = NRF_SPIM_MODE_0;
        spim_config.bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST;
        spim_config.skip_gpio_cfg = true;
        spim_config.skip_psel_cfg = true;
        spim_config.ss_active_high = false;

        status = pinctrl_apply_state(PINCTRL_DT_DEV_CONFIG_GET(SPI_NODE_RHS),
                                     PINCTRL_STATE_DEFAULT);
        if (status != 0)
        {
                LOG_ERR("Could not pinctrl_apply_state %X", status);
                return;
        }

        /* Set initial state of SCK according to the SPI mode. */
        u32_t sck_pin = nrf_spim_sck_pin_get(spim_inst.p_reg);
        u32_t mosi_pin = nrf_spim_mosi_pin_get(spim_inst.p_reg);
        u32_t miso_pin = nrf_spim_miso_pin_get(spim_inst.p_reg);
        LOG_INF("SCK pin: %d, MOSI pin: %d, MISO pin: %d", sck_pin, mosi_pin, miso_pin);

        if (sck_pin != NRF_SPIM_PIN_NOT_CONNECTED)
        {
                nrfy_gpio_pin_write(sck_pin, NRF_SPIM_MODE_0);
        }

        nrf_spim_csn_configure(spim_inst.p_reg, NRF_DT_GPIOS_TO_PSEL(SPI_NODE_RHS, cs_gpios), NRF_SPIM_CSN_POL_LOW, 2);

        status = nrfx_spim_init(&spim_inst, &spim_config, NULL, NULL);

        if (status != NRFX_SUCCESS)
        {
                LOG_ERR("Could not get spi_dev_rhs device - err %X", status);
                return;
        }
        LOG_INF("Device spi_dev_rhs Correctly configured!");

Whenever I configure the SPI to work at 8 MHz I don't have any issue, but when I try the 24 MHz (which is the frequency I need since the external device has a maximum speed of 25 MHz), I get and error on the function "nrfx_spim_init" with code 0xBAD0004 and the NRFX_LOG explicitly says "NRFX_SPIM: Function: spim_configuration_verify, error code: NRFX_ERROR_INVALID_PARAM."

Any suggestion?

Parents Reply Children
Related