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

SPI communication between nRF9160DK and nRF52840DK

Hello,

I want to transfer data from nRF52840DK to nRF9160DK using SPI. I want to use nRF52840DK as master which will transfer the data and nRF9160DK as slave which will receive the data.

I have never worked with nRF52840DK. For SPI master, I tried SPI example on nRF52840DK. When I connect MOSI to MISO, the data is transferred. Now I want to transfer this data to nRF9160DK.

On nRF9160DK, I tried SPI master example to check if it works. Now I want to use nRF91 as SPI slave. So I added spi slave drivers and changed overlay file also. But I am not understanding how to configure spi_config struct for slave.

static const struct spi_config spi_cfg = {
//	.operation = SPI_OP_MODE_SLAVE | SPI_MODE_CPOL | SPI_MODE_CPHA,
        .operation = SPI_OP_MODE_SLAVE,
	.frequency = 4000000,
	//.slave = 1,

};

I am not understanding how to set these parameters to configure spi in slave and receive the data.

I connected both the dks to check if nrf91 can receive the data, but spi_read shows error

Parents Reply Children
  • Thank you for the documentation.

    Yes I was looking for Zephyr SPI driver as well as nrf drivers for nRF52 also. I tried the spi programs on both the DKs. Separately they are working properly. But when I try to read from nrf52 on nrf91, it shows error. So now I am switching to I2C. I2C communication is good between both the DKs. I can receive data from nrf52.

    But still curious why spi did not work together.

  • Jagruti said:
    Thank you for the documentation.

    No problem at all, I am happy to help!

    Jagruti said:
    Separately they are working properly.

    What do you mean when you say this; do you mean that the performance was as expected when you flashed one device with the SPI Slave example, and another one with the SPI Master example?

    Jagruti said:
    I2C communication is good between both the DKs.

    I am glad to hear that you have achieve the communication you were after.
    If required, I would not think setting up SPI should prove to be a large endeavor.

    Best regards,
    Karl

  • Yes the performance was as expected when I flashed SPI master example on nrf52 and as well as on nrf91. On nrf91, I used zephyr spi drivers. But when I connected nrf91 spi salve to nrf52 spi master. The data was not received on nrf91. There was error on nrf91 side. I think I did not configure nrf91 as spi slave properly. That's why the error is coming and there is no communication between nrf52 and nrf91. I have not yet understood how to the configuration for spi slave. I must be missing something.

  • I see.
    If you would share the relevant code you have written to configure your nRF9160 as SPI Slave, I could take a look.

    Do you configure it as SPI_OP_MODE_SLAVE in the SPI config?
    The different configuration parameters are detailed in the Zephyr SPI API Reference I linked earlier.

    Best regards,
    Karl

  • I read the SPI API reference. But still few things were unclear.

    My spi config struct looks like this:

    static const struct spi_config spi_cfg = {
    //	.operation = SPI_OP_MODE_SLAVE | SPI_MODE_CPOL | SPI_MODE_CPHA,
            .operation = SPI_OP_MODE_SLAVE,
    	.frequency = 4000000,
    	//.slave = 1,
    
    };

    I did not understand how to set other parameters. As it is a slave, the cs pin will be active_low. But how to set the spi mode that I did not understand and even in .slave parameter what value goes, that is also not clear to me. While configuring master, it was set to 0.

Related