when I use following code for SPI connection I will be notice this error
what is the matter?
#include <zephyr/kernel.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
#define LED1_NODE DT_ALIAS(led1)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
static const struct spi_config spi_cfg = {
.operation = SPI_WORD_SET(8),
.frequency = 4000000,
.slave = 0,
};
struct device * spi_dev;
static void spi_init(void)
{
const char* const spiName = "SPI_0";
spi_dev = device_get_binding(spiName);
if (spi_dev == NULL) {
printk("Could not get %s device\n", spiName);
return;
}
}
void spi_test_send(void)
{
int err;
static uint8_t tx_buffer[1];
static uint8_t rx_buffer[1];
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
};
err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
if (err) {
printk("SPI error: %d\n", err);
} else {
/* Connect MISO to MOSI for loopback */
printk("TX sent: %x\n", tx_buffer[0]);
printk("RX recv: %x\n", rx_buffer[0]);
tx_buffer[0]++;
}
}
void main(void)
{
printk("SPIM Example\n");
spi_init();
while (1) {
spi_test_send();
k_sleep(K_MSEC(1000));
}
}