SPI Communication SDK 2.4.0 nRF5340 DK

Hello,

I want to operate a rather complex spi sensor with the nrf5340. To do that, I wanted to first establish spi communication. I started by creating a hello world example and then implementing the steps explained in the spi API tutorial. This is my current main.c:

 

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/kernel.h>


#include <zephyr/devicetree.h>
#include <zephyr/drivers/spi.h>

#define SPIOP	SPI_WORD_SET(8) | SPI_TRANSFER_MSB
// const struct device *const spi_dev = DEVICE_DT_GET(DT_NODELABEL(spi1));
const struct spi_dt_spec *const spispec = DEVICE_DT_GET(DT_NODELABEL(spi4));
// struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spi1), SPIOP, 0);

int main(void)
{
	uint32_t err;

	err = spi_is_ready_dt(&spispec);
	if (!err) {
		// LOG_ERR("Error: SPI device is not ready, err: %d", err);
		return 0;
	}

	uint8_t data[8], size, data2[8];
	data2[0] = 3;

	// while (true)
	// {
	// 	err = spi_write_dt(spispec, data);
		
	// }

	uint8_t tx_buffer = 0x88;
	struct spi_buf tx_spi_buf		= {.buf = (void *)&tx_buffer, .len = 1};
	struct spi_buf_set tx_spi_buf_set 	= {.buffers = &tx_spi_buf, .count = 1};
	struct spi_buf rx_spi_bufs 		= {.buf = data, .len = size};
	struct spi_buf_set rx_spi_buf_set	= {.buffers = &rx_spi_bufs, .count = 1};

	while (true)
	{
		/* code */
	err = spi_write_dt(&spispec, &data2);
	
	err = spi_transceive_dt(&spispec, &tx_spi_buf_set, &rx_spi_buf_set);
	if (err < 0) {
		LOG_ERR("spi_transceive_dt() failed, err: %d", err);
		return err;
		}

		k_msleep(10);
	
	}

	


	printk("Hello World! %s\n", CONFIG_BOARD);
	return 0;
}

I did set the SPI config in my proj.conf.

I wanted to check with a logic analyzer if anything is happening on my mosi and miso lines, so I connected it to the default spi4 pins: P1.13 for MOSI, P1.14 for MISO and P1.15 for SCK. I checked in the devie tree and the pins are correct. However, nothing is happening on the MISO, MOSI, or SCK lines.
I do not have a Sensor attached, i just want to check if anything is happening at all.

Can someone help me out here?

Thanks,

Paul

Parents
  • I may need to add that I did not create the overlay file with the following as it was told in the tutorial

    &spi1 {
            compatible = "nordic,nrf-spi";
            status = "okay";
            cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
            pinctrl-0 = <&spi1_default>;
            pinctrl-1 = <&spi1_sleep>;
            pinctrl-names = "default", "sleep";
            gendev: gendev@0 {
                    compatible = "vnd,spi-device";
                    reg = <0>;
                    spi-max-frequency = <1600000>;
                    label = "GenDev";
            };
    };

    I tried doing that, but (I did change spi1 to spi4) it keeps shooting our errors if I do that.

    Instead, I used spi4 directly.

Reply
  • I may need to add that I did not create the overlay file with the following as it was told in the tutorial

    &spi1 {
            compatible = "nordic,nrf-spi";
            status = "okay";
            cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
            pinctrl-0 = <&spi1_default>;
            pinctrl-1 = <&spi1_sleep>;
            pinctrl-names = "default", "sleep";
            gendev: gendev@0 {
                    compatible = "vnd,spi-device";
                    reg = <0>;
                    spi-max-frequency = <1600000>;
                    label = "GenDev";
            };
    };

    I tried doing that, but (I did change spi1 to spi4) it keeps shooting our errors if I do that.

    Instead, I used spi4 directly.

Children
Related