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

SPIM pins config fail

I try to use the SPIM0 but the configuration of the pins fail, the value in PSEL doesn't change after the call to nrfx_spim_init().

#include <assert.h>
#include <stdint.h>
#include <zephyr.h>
#include <nrfx_spim.h>

#define SCLK_PIN NRF_GPIO_PIN_MAP(0, 8)
#define MOSI_PIN NRF_GPIO_PIN_MAP(0, 9)
#define MISO_PIN NRF_GPIO_PIN_MAP(0,10)
#define CS_PIN   NRF_GPIO_PIN_MAP(0,11)

#define SPI_TRANSFER_SIZE 2

static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(0);
static uint8_t tx_buffer[SPI_TRANSFER_SIZE];
static const nrfx_spim_xfer_desc_t xfer = NRFX_SPIM_XFER_TX(tx_buffer, SPI_TRANSFER_SIZE);

void main(void)
{
    nrfx_err_t err_code;

    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(SCLK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);
    err_code = nrfx_spim_init(&spi, &spi_config, NULL, NULL);
    assert(err_code == NRFX_SUCCESS);

    while (1) {
        err_code = nrfx_spim_xfer(&spi, &xfer, NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER);
        assert(err_code == NRFX_SUCCESS);
        k_sleep(K_MSEC(1));
    }
}

Parents Reply Children
  • Hello again, Nicolas!

    I believe I have tracked down the issue. Some peripherals, like UART0 and SPIM0 cannot be active at the same time. Hence, I recommend that you use SPIM1. However, if you want to use SPIM0 you have to apply an overlay file to the project in order to disable UART0. I've attached the one I used to make it work: 

    &spi0 {
      status = "okay";
      label = "SPI_0"; 
    };
    
    &uart0 {
        status = "disabled";
    };
    
    &uart1 {
        compatible = "nordic,nrf-uarte";
        status = "okay";
        label = "UART_1";
        current-speed = < 0x1c200 >;
        tx-pin = < 0x14 >;
        rx-pin = < 0x16 >;
        rts-pin = < 0x13 >;
        cts-pin = < 0x15 >;
    };
    

    Place this file in your project directory, and change the type from ".txt" to ".overlay". Note that I've enabled UART1 with the same configuration as UART0 in order to get serial output.

    Hope this works for you!

    Best regards,
    Carl Richard

Related