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