Hello
I actually have hard time moving from NRF51 to NRF52.
While learning new things I got stuck with SPI configuration and I couldn't find any help on the internet.
I am using NRF52DK with NRF52832
My project is based on observer example.
My prj.conf is
CONFIG_BT=y CONFIG_BT_OBSERVER=y CONFIG_SPI=y
nrf52dk_nrf52832.dts has this. I want to use spi2 for my example
arduino_spi: &spi2 {
compatible = "nordic,nrf-spi";
status = "okay";
sck-pin = <25>;
mosi-pin = <23>;
miso-pin = <24>;
cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */
};
My main.c is
#include <zephyr/types.h>
#include <stddef.h>
#include <sys/printk.h>
#include <sys/util.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/spi.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#define SPI_EPAPER_NODE DT_NODELABEL(arduino_spi)
void main(void)
{
const struct device *epd_spi;
epd_spi = device_get_binding(DT_LABEL(SPI_EPAPER_NODE));
if (!epd_spi)
{
printk("SPI bitbang driver %s was not found!\n",
DT_LABEL(SPI_EPAPER_NODE));
return;
}
struct spi_config config;
config.frequency = 10000;
config.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) ;
config.slave = 0;
config.cs = NULL;
enum { datacount = 5 };
uint8_t buff[datacount] = { 0x01, 0x02, 0x03, 0x04, 0x05};
uint8_t rxdata[datacount] = {0};
struct spi_buf tx_buf[1] = {
{.buf = buff, .len = datacount},
};
struct spi_buf rx_buf[1] = {
{.buf = rxdata, .len = datacount},
};
struct spi_buf_set tx_set = { .buffers = tx_buf, .count = 1 };
struct spi_buf_set rx_set = { .buffers = rx_buf, .count = 1 };
int ret = spi_transceive(epd_spi, &config, &tx_set, &rx_set);
printk("8bit_loopbahck_partial; ret: %d\n", ret);
printk(" tx (i) : %02x %02x %02x %02x %02x\n",
buff[0], buff[1], buff[2], buff[3], buff[4]);
printk(" rx (i) : %02x %02x %02x %02x %02x\n",
rxdata[0], rxdata[1], rxdata[2], rxdata[3], rxdata[4]);
}
I have nothing connected to the device. I just flashed it and return value of spi_transceive is -22 which is EINVAL error.
What am I doing wrong?