Can anyone please provide nRF9160 SPI slave Example code?
Thanks,
-Ankit
Can anyone please provide nRF9160 SPI slave Example code?
Thanks,
-Ankit
Sample code link you have given is for SPI master. i need SPI slave code
Hi.
If you mean that there is no sample for SPIS, then; you are right, there's no sample specifically for SPIS.
The drivers and port files are present in zephyr:
https://github.com/NordicPlayground/fw-nrfconnect-zephyr/blob/master/drivers/spi/spi_nrfx_spis.c
To enable the module, here with enabling SPIS 3, you can add this to your prj.conf file:
# SPI CONFIG_SPI=y CONFIG_SPI_SLAVE=y CONFIG_SPI_3_NRF_SPIS=y # 2 = slave only CONFIG_SPI_3_OP_MODES=2
Note: add "CONFIG_SPI_ASYNC=y" for asynchronous SPIS operation.
And you'll also need to set which GPIOs to use and other settings, typically in your project_folder/nrf9160_pca10090ns.overlay (Note, new overlay settings!):
&spi3 { compatible = "nordic,nrf-spis"; status = "okay"; sck-pin = <10>; mosi-pin = <11>; miso-pin = <12>; csn-pin = <13>; def-char = <0x00>; };
Best regards,
Andreas
Hi.
If you mean that there is no sample for SPIS, then; you are right, there's no sample specifically for SPIS.
The drivers and port files are present in zephyr:
https://github.com/NordicPlayground/fw-nrfconnect-zephyr/blob/master/drivers/spi/spi_nrfx_spis.c
To enable the module, here with enabling SPIS 3, you can add this to your prj.conf file:
# SPI CONFIG_SPI=y CONFIG_SPI_SLAVE=y CONFIG_SPI_3_NRF_SPIS=y # 2 = slave only CONFIG_SPI_3_OP_MODES=2
Note: add "CONFIG_SPI_ASYNC=y" for asynchronous SPIS operation.
And you'll also need to set which GPIOs to use and other settings, typically in your project_folder/nrf9160_pca10090ns.overlay (Note, new overlay settings!):
&spi3 { compatible = "nordic,nrf-spis"; status = "okay"; sck-pin = <10>; mosi-pin = <11>; miso-pin = <12>; csn-pin = <13>; def-char = <0x00>; };
Best regards,
Andreas
I have defined the pin mapping of SPI in the overlay file, but when I load my application in SES, it has such an error. What is the cause of this?
the overlay file is like this:
&spi3 {
status = "okay";
sck-pin = <15>;
mosi-pin = <14>;
miso-pin = <13>;
spi-max-frequency = <4000000>;
};
and the SES report this error:
devicetree error:'spi-max-frequency' appears in /soc/peripheral@40000000/spi@b000 in nrf9160_pca10090ns.dts.pre.tmp,but is not declared in 'properties:' in D:/software/nrf9160/ncs/zephyr/dts/bindings\spi\nordic,nrf-spim.yaml
If you are going to implement SPI Slave, Below setting will work:
in nrf9160_pca10090ns.overlay file:
&spi3 {
compatible = "nordic,nrf-spis";
status = "okay";
sck-pin = <13>;
mosi-pin = <11>;
miso-pin = <12>;
csn-pin = <10>;
def-char = <0x00>;
};
in prj.conf file:
# SPI
#CONFIG_SPI=y
#CONFIG_SPI_SLAVE=y
#CONFIG_SPI_3_NRF_SPIS=y
# 2 = slave only
#CONFIG_SPI_3_OP_MODES=2
#CONFIG_SPI_ASYNC=y
Note: when proj.config file is changed, reopen project.