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

Getting started with spi and i2c on nrf connect sdk

Hi,

I have been working with nrf5 sdk for my projects and now i am trying to port it into the nrfconnect sdk.

It looks a bit confusing and not able to find the proper documentation channels to add spi communication to my sample project. I have seen some of the posts here that looks out dated.

I couldn't make any progress in communicating with my device over spi or twi. 

What is simplest way to add an spi sensor ?

Parents
  • There are no silly questions, only silly answers. Right? ;-)

    Are you using your own board together with the nRF52840 or a DK? I am asking because if you work with the nRF52840 DK for instance, you do not need an overlay file to get SPI1 to work. It is already part of the device tree, which you can check via a file called zephyr.dts located in: ../<your build folder>/zephyr/.

     

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

    I ran your C-snippet through a simple “Hello World” application on the nRF52840 DK and the binding worked fine.

    Regards,

    Markus

  • I am using a custom board based on nrf52840.

    I have not created a new board but edited the existing .dts file according my custom board specifications.

    I have ran it on a dk also but getting the same error.

    i have chosen a ble code as my base, let me get back to you after trying it out with simple example.

    This how the zephyr.dts file looks like,

    		};
    		spi0: spi@40003000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40003000 0x1000 >;
    			interrupts = < 0x3 0x1 >;
    			status = "disabled";
    			label = "SPI_0";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0x1f >;
    			mosi-pin = < 0x1e >;
    			miso-pin = < 0x28 >;
    		};
    		spi1: spi@40004000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40004000 0x1000 >;
    			interrupts = < 0x4 0x1 >;
    			status = "okay";
    			label = "SPI_1";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0xd >;
    			mosi-pin = < 0xe >;
    			miso-pin = < 0x10 >;
    		};
    		spi2: spi@40023000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40023000 0x1000 >;
    			interrupts = < 0x23 0x1 >;
    			status = "disabled";
    			label = "SPI_2";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0x13 >;
    			mosi-pin = < 0x14 >;
    			miso-pin = < 0x15 >;
    		};

    How do i create an overlay file ?

Reply
  • I am using a custom board based on nrf52840.

    I have not created a new board but edited the existing .dts file according my custom board specifications.

    I have ran it on a dk also but getting the same error.

    i have chosen a ble code as my base, let me get back to you after trying it out with simple example.

    This how the zephyr.dts file looks like,

    		};
    		spi0: spi@40003000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40003000 0x1000 >;
    			interrupts = < 0x3 0x1 >;
    			status = "disabled";
    			label = "SPI_0";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0x1f >;
    			mosi-pin = < 0x1e >;
    			miso-pin = < 0x28 >;
    		};
    		spi1: spi@40004000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40004000 0x1000 >;
    			interrupts = < 0x4 0x1 >;
    			status = "okay";
    			label = "SPI_1";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0xd >;
    			mosi-pin = < 0xe >;
    			miso-pin = < 0x10 >;
    		};
    		spi2: spi@40023000 {
    			#address-cells = < 0x1 >;
    			#size-cells = < 0x0 >;
    			reg = < 0x40023000 0x1000 >;
    			interrupts = < 0x23 0x1 >;
    			status = "disabled";
    			label = "SPI_2";
    			compatible = "nordic,nrf-spi";
    			sck-pin = < 0x13 >;
    			mosi-pin = < 0x14 >;
    			miso-pin = < 0x15 >;
    		};

    How do i create an overlay file ?

Children
No Data
Related