This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPIS cannot receive data (using nRF Connect SDK, Zephyr)

Hi; I'm trying to develop an application with the nrf52840 as a co-processor. We decided to use the nrf52 as a SPI slave and a SAMD21 as a SPI master. I set up a quick Arduino sketch on the SAMD21 to try to communicate with the device.

I set up a SPIS device with this in my config:

CONFIG_SPI=y
#CONFIG_SPI_ASYNC=y
CONFIG_SPI_LOG_LEVEL_INF=y
CONFIG_SPI_0=y
CONFIG_SPI_SLAVE=y
CONFIG_SPI_NRFX=y
CONFIG_SPI_0_NRF_SPIS=y
My overlay file is:
&spi0 {
	compatible = "nordic,nrf-spis";
	status = "okay";
	sck-pin = <26>;
	mosi-pin = <29>;
	miso-pin = <30>;
	csn-pin = <31>;
	def-char = <0x00>;
};
I've set up a polling thread to check the SPI bus for transactions. 
static int spis_init(void) {
  spis_dev = device_get_binding(DT_ALIAS_SPI_0_LABEL);
  if (!spis_dev){
	  LOG_ERR("MISSING SPIS DEVICE");
	  return -EINVAL;
  }
  return 0;
}

static u8_t txmsg[SPI_MAX_MSG_LEN] = "sample";
static u8_t rxmsg[SPI_MAX_MSG_LEN];
static void spis_thread(void *p1, void *p2, void *p3) {
  ARG_UNUSED(p1);
  ARG_UNUSED(p2);
  ARG_UNUSED(p3);
  int err;
  for (;;) {
    tx.buf = txmsg;
    tx.len = 250;
    rx.buf = rxmsg;
    tx.len = 250;
    err = spi_transceive(spis_dev, &spi_cfg, &tx_bufs, &rx_bufs);
    if (err >= 0) {
      LOG_ERR("stuff: %s %s %d", log_strdup(txmsg), log_strdup(rxmsg), err);
    }
  }
}


void main(void) {
  int err;
  k_tid_t spis_id;

  err = spis_init();
  if (err != 0) {
    LOG_WRN("SPIS device fail");
    return;
  }

/**
* Set up other devices etc... 
*/

	spis_id = k_thread_create(&spis_thread_data, spis_thread_stack,
				K_THREAD_STACK_SIZEOF(spis_thread_stack),
				spis_thread, NULL, NULL, NULL, K_PRIO_COOP(7),
				0, K_NO_WAIT);
	k_thread_name_set(&spis_thread_data, "spis_thread");

  u32_t dtr = 0U;
  while (1) {
    if (!dtr) {
      uart_line_ctrl_get(usb_dev, UART_LINE_CTRL_DTR, &dtr);
    }
    k_usleep(1000);
  }
}
The SAMD21 receives the "sample" string on sending information through, but the nRF doesn't receive any data. Adding debug statements to the SPIS event handler shows that p_event->rx_amount == 0 on NRFX_SPIS_XFER_DONE, but instrumenting the SPI bus with a logic analyzer shows both messages sent on MISO and MOSI lines at the correct voltage levels.
Are there any suggestions as to what the problem might be?
Parents Reply Children
No Data
Related