How to configure the SPIM if i have defined my MOSI/MISO/SCK pins in the device overlay file, shown below:
&pinctrl {
spi0_default: spi0_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 26)>,
<NRF_PSEL(SPIM_MISO, 0, 30)>;
};
};
spi0_sleep: spi0_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 26)>,
<NRF_PSEL(SPIM_MISO, 0, 30)>;
};
};
};
&spi0 {
status = "okay";
pinctrl-0 = <&spi0_default>;
pinctrl-1 = <&spi0_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
};
and in the main.c file this, how I am configuring it
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <nrfx_spim.h>
#define SPI_NODE DT_NODELABEL(spi0)
const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(0);
nrfx_spim_config_t cfg = {
.sck_pin = NRFX_SPIM_PIN_NOT_USED,
.mosi_pin = NRFX_SPIM_PIN_NOT_USED,
.miso_pin = NRFX_SPIM_PIN_NOT_USED,
.ss_pin = NRFX_SPIM_PIN_NOT_USED,
.frequency = NRF_SPIM_FREQ_8M,
.mode = NRF_SPIM_MODE_0,
.bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST,
};
nrfx_spim_init(&spi, &cfg, NULL, NULL);
But, apparently, no movement on the SCK pins. I am controlling the CS pin via GPIO, which is toggling at the given frequency. I am unable to connect my device overlay to the SPIM configuration. What am I missing?
However, it's working fine if I am defining the macros of all these pins and providing those macros in the config of spim, shown below:
#define SPIM_MISO_PIN 30
#define SPIM_SCK_PIN 26
#define SPIM_CS_PIN 29
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(SPIM_SCK_PIN,
NRF_SPIM_PIN_NOT_CONNECTED,
SPIM_MISO_PIN,
NRF_SPIM_PIN_NOT_CONNECTED);
spi_config.sck_pin = SPIM_SCK_PIN;
spi_config.mosi_pin = NRF_SPIM_PIN_NOT_CONNECTED; // No MOSI pin
spi_config.miso_pin = SPIM_MISO_PIN;
spi_config.ss_pin = NRF_SPIM_PIN_NOT_CONNECTED; // No SS pin, using GPIOTE to toggle CNVST pin
spi_config.mode = NRF_SPIM_MODE_1; // CPOL = 0, CPHA = 1
spi_config.frequency = NRFX_MHZ_TO_HZ(8); // 8MHz
Thanks