Zephyr nRF52840
I am working with 2 nRF52840dk. The master side seems to be working as expected. i have monitored it and seen clock, MOSI and CS all working as expected on a scope
The slave is non-responsive. Even though i should be seeing a printout i am getting nothing. and i dont even think the slave is reacting at all because my MISO line does nothing also. and form what i am understanding with the spi_transceive and def-chr value. if i have an empty buffer i should be outputting 0x33
i think it has something to do with the fact i am unable to get csn-pin to compile for some reason so the slave is not responding to the CS activity
overlay - 1 thing, even though nordic,nrf-spis has a csn-pin in its struct, i get an error when i try and set it. error i get below
&pinctrl { spi2_default: spi2_default { group1 { psels = <NRF_PSEL(SPIS_SCK, 0, 19)>, <NRF_PSEL(SPIS_MOSI, 0, 20)>, <NRF_PSEL(SPIS_MISO, 0, 21)>; }; }; spi2_sleep: spi2_sleep { group1 { psels = <NRF_PSEL(SPIS_SCK, 0, 19)>, <NRF_PSEL(SPIS_MOSI, 0, 20)>, <NRF_PSEL(SPIS_MISO, 0, 21)>; low-power-enable; }; }; }; &spi2 { compatible = "nordic,nrf-spis"; status = "okay"; pinctrl-0 = <&spi2_default>; pinctrl-1 = <&spi2_sleep>; pinctrl-names = "default", "sleep"; //csn-pin = <4>; cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; def-char = <0x33>; };
proj.conf - i just posted everything in my proj file in case there was a conflict. the SPI assertions are at the bottom though
# Enable the BLE stack with GATT Client configuration CONFIG_BT=y CONFIG_BT_DEBUG_LOG=y CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=y CONFIG_BT_GATT_CLIENT=y # Enable the BLE modules from NCS CONFIG_BT_NUS_CLIENT=y CONFIG_BT_SCAN=y CONFIG_BT_SCAN_FILTER_ENABLE=y CONFIG_BT_SCAN_UUID_CNT=1 CONFIG_BT_GATT_DM=y CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_BT_FILTER_ACCEPT_LIST=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_DIS=y CONFIG_BT_DIS_PNP=n CONFIG_BT_DEVICE_NAME="RLU" CONFIG_BT_DEVICE_APPEARANCE=768 CONFIG_BT_DEVICE_NAME_DYNAMIC=y CONFIG_BT_ATT_ENFORCE_FLOW=n CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_BT_HRS=y CONFIG_BT_BAS=y # Enable bonding CONFIG_BT_BONDABLE=y CONFIG_SETTINGS=y CONFIG_BT_SETTINGS=y CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_NVS=y # SPI CONFIG_SPI=y CONFIG_SPI_SLAVE=y
Error i get when i try and use csn-pin
from C:\ncs\v2.0.0\zephyr\include\zephyr\drivers\spi.h:24, from C:\ncs\v2.0.0\zephyr\drivers\spi\spi_nrfx_spis.c:7: C:\ncs\v2.0.0\zephyr\include\zephyr\toolchain\gcc.h:77:36: error: static assertion failed: "/soc/spi@40023000 has legacy *-pin properties defined although PINCTRL is enabled" 77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG) | ^~~~~~~~~~~~~~ c:\ncs\v2.0.0\zephyr\soc\arm\nordic_nrf\common\soc_nrf_common.h:229:2: note: in expansion of macro 'BUILD_ASSERT' 229 | BUILD_ASSERT(!IS_ENABLED(CONFIG_PINCTRL) || \
Now my spis.c file seems like this should work but it is not printing out anything and not sure how to confirm if the thread is still running or anything. But I would assume it should just output to printk whatever data it received on the MOSI line. However it prints nothing.
#include "spis.h" #include <zephyr.h> #include <sys/printk.h> #include <drivers/spi.h> #include <device.h> #define SPIS_NODE DT_NODELABEL(spi2) extern void spis_thread(void *, void *, void *); K_THREAD_DEFINE(spis_tid, SPIS_STACK_SIZE, spis_thread, NULL, NULL, NULL, SPIS_PRIORITY, 0, 0); struct spis_cb_t spi_cb; static uint8_t spis_tx_buffer[SPI_BUFFER_SIZE] = "<*>slave out default message buf"; static uint8_t spis_rx_buffer[SPI_BUFFER_SIZE]; static struct spi_config spis_cfg = { .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_SLAVE | SPI_MODE_CPOL | SPI_MODE_CPHA, .frequency = 125000, .slave = 1, }; const struct spi_buf spis_tx_buf = { .buf = spis_tx_buffer, .len = sizeof(spis_tx_buffer) }; const struct spi_buf_set spis_tx = { .buffers = &spis_tx_buf, .count = 1 }; const struct spi_buf spis_rx_buf = { .buf = spis_rx_buffer, .len = sizeof(spis_rx_buffer), }; const struct spi_buf_set spis_rx = { .buffers = &spis_rx_buf, .count = 1 }; const struct device * spis_dev; uint8_t spis_init(void) { spis_dev = device_get_binding(DT_LABEL(SPIS_NODE)); if (spis_dev == NULL) { printk("Could not get %s device\n", DT_LABEL(SPIS_NODE)); return 1; } printk("SPI Device: %s\n", DT_LABEL(SPIS_NODE)); return 0; } void spis_transceive(void){ int cnt = 0; uint8_t incr = 0; cnt = spi_transceive(spis_dev, &spis_cfg, NULL, &spis_rx); // &spis_tx where NULL is if(cnt > 0){ while(incr < SPI_BUFFER_SIZE){ printk("%c", spis_rx_buffer[incr]); incr++; } printk("\n"); } } extern void spis_thread(void *unused1, void *unused2, void *unused3){ int err; err = spis_init(); if(err) return; printk("SPIS thread begin\n"); while (1) { spis_transceive(); } printk("SPIS thread end\n"); }
It definitely looks like the thread is starting though. SPI Device: SPI_2 shows it registered devce and SPIS thread begin was my call to show thread started
SPI Device: SPI_2 SPIS thread bBluetooth initialized My Client module initialized egin Successfully started asset tracking advert Scanning successfully started