Hello, I've been trying to launch zephyr SPI example, but I'm having issues with SPI sending anything. The code itself does not throw any errors, and it seems like my board does execute spi_transceive function, but nothing on osciloscope. I'm not worried about CS at the moment, I just want to see any activity from SPI on Osciloscope. The code is fairly simple:
#include <zephyr.h> #include <device.h> #include <devicetree.h> #include <drivers/gpio.h> #include <drivers/spi.h> #define SLEEP_TIME_MS 100 #define RECEIVE_BUFF_SIZE 10 #define RECEIVE_TIMEOUT 100 /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) #define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) #define PIN DT_GPIO_PIN(LED0_NODE, gpios) #define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) struct device * spi_dev; static void spi_init(void) { const char* const spiName = "SPI_0"; spi_dev = device_get_binding(spiName); } static const struct spi_config spi_cfg = { .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA, .frequency = 4000000, .slave = 0, }; void spi_test_send(const struct device *dev) { int err; static uint8_t tx_buffer[100] = "hello"; static uint8_t rx_buffer[100]; gpio_pin_toggle(dev,PIN); const struct spi_buf tx_buf = { .buf = tx_buffer, .len = sizeof(tx_buffer) }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; struct spi_buf rx_buf = { .buf = rx_buffer, .len = sizeof(rx_buffer), }; const struct spi_buf_set rx = { .buffers = &rx_buf, .count = 1 }; spi_transceive(spi_dev, &spi_cfg, &tx, &rx); //tx_buffer[0]++; } void main(void) { const struct device *dev; dev = device_get_binding(LED0); gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); spi_init(); while (1) { spi_test_send(dev); k_msleep(SLEEP_TIME_MS); } }
config file:
CONFIG_GPIO=y CONFIG_SPI=y
dts file:
&spi0 { compatible = "nordic,nrf-spis"; /* Cannot be used together with i2c0. */ status = "okay"; sck-pin = <27>; mosi-pin = <26>; miso-pin = <28>; csn-pin = <31>; def-char = <0x00>; };
Could someone glance over the code and tell me what am I doing wrong? Maybe it's a simple overlook from my side.