How to use SPI for nRF52840 DK and nRF Connect SDK

Hi, I'm Leo.

These days I'm learning BLE.

First, I'm using nRF Connect SDK(NCS) v1.9.1, S140, nRF52840 DK board.

I need to use SPI to control UWB transceiver(DWM3000). As far as I searched, there's no example of what I need.

I want to use NCS because I've studied this. It not, I have to learn SES version API, right? 

Here're my questions.

0. Can I use NCS for SPI? Or must I use nRF5 SDK?

1. If it is okay to use NCS for SPI, then do I have to set Zephyr for NCS?

2. Then, how to configure?

Sorry to talk gibberish. It's hard to understand overall.

I find some codes for SPI but it is really confusing.

This is *.overlay file. I think it is all I need to revise.

&spi1 {
	compatible = "nordic,nrf-spis";
	status = "okay";
	sck-pin = <15>;
	miso-pin = <14>;
	mosi-pin = <13>;
	csn-pin = <12>;
	def-char = <0x00>;

	// bt-hci@0 {
	// 	compatible = "zephyr,bt-hci-spi-slave";
	// 	reg = <0>;
	// 	irq-gpios = <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
	// };
};

How to set the pin number? There're many pins but I only can type number.

This is zephyr.dts code for NRF52840.

spi1: spi@40004000 {
	compatible = "nordic,nrf-spi";
	#address-cells = < 0x1 >;
	#size-cells = < 0x0 >;
	reg = < 0x40004000 0x1000 >;
	interrupts = < 0x4 0x1 >;
	status = "okay";
	label = "SPI_1";
	sck-pin = < 0x1f >;
	mosi-pin = < 0x1e >;
	miso-pin = < 0x28 >;
};

This is prj.conf file.

CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_SLAVE=y
CONFIG_MAIN_STACK_SIZE=512
CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_MAX_CONN=16
CONFIG_BT_TINYCRYPT_ECC=n
CONFIG_BT_BUF_ACL_RX_COUNT=10
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_HCI_RAW_RESERVE=1

So, are these things all to configure?

How to use SPI in order to activate UWB transceiver?

I'm sincerely sorry, I'm a mess comprehending all the things. There isn't someone to help this around me. 

Please help me. I'll wait for your kind answer.

  • Hi,

    Could you try being a little more clear about what it is you are trying to achieve?

    0. Can I use NCS for SPI? Or must I use nRF5 SDK?

    Yes, NCS is a complete SDK, and supports pretty much every major feature that the nRF5 SDK supports.

    1. If it is okay to use NCS for SPI, then do I have to set Zephyr for NCS?

    I am not entirely sure what you mean when you say "set Zephyr for NCS". Zephyr is the core part of NCS, and you can not use NCS without Zephyr.

    2. Then, how to configure?

    Using an overlay file is the recommended method.
    The numbers for the pins use this system: 0 means P0.00, 31 means P0.31, 32 means P1.00, and 47 means P1.15.

    How to use SPI in order to activate UWB transceiver?

    I assume the transceiver is an SPI slave? And you want the nrf52840 to be the SPI master?

    The best approach would probably be to write a driver for the device, based on existing drivers for similar devices.

  • I'm really thankful for your answer.

    Please understand if I use awkward words. I'm new and bad at an embedded field. And also writing questions and comments on the public sites is also new. So I don't know what is appropriate words or expressions and approaches. 

    Yes, you're right. My UWB transceiver is SPI-slave, so I need to use nRF52840 DK board as a SPI-master.

    I saw there are some settings like spi, spi-s, spi-m. And spi-m was more recent setting, right?

    I don't know how to write a driver and actually it is quite confusing what is the driver. So I'll explain by myself, please check it is right.

    Drivers are particular software codes for controlling the hardware(devices like a board, sensor, actuator...). Then how to make it? I also heard about kernel for communication between hardware and software. What's the difference?

    Porting is setting the port(pin on the board) as I want to use like GPIO, SPI, I2C, UART... right? So I have to tune or coordinate for the standard like a protocol. 

    I don't know how much I need to modify to use SPI on Zephyr. I think that's a point. I learned a little about CMake, Ninja, DeviceTree, and all that jazz for Zephyr RTOS. But I'm not aware of what has an important role to fit in my situation. Too many things to learn... omg

    Oh, I also want to use BLE at the same time I'm using UWB (and UART, SPI, and so on...) Is it possible?? I don't know it can work together in the same code, I mean in one (main) code.

    There are many libraries and APIs such as DK_buttons and LED, UART, Zephyr, Bluetooth, GAP... I think it could be possible to mix but I don't know how to unify and what is the dependency on each other.

    Again, thanks a lot for your kind answer. Tell me if I'm wrong and what is the missing point.

    Best regards.

Related