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

Migrating a design from Raspberry pi Zero to nRF9160 DK - Need I2C and SPI interfaces

Hi,

I have developed a simple system based around a Raspberry Pi Zero. The system uses a couple of sensors to measure temperature and water pressure using a ADS51115 A/D and a MAX 31865 RTD to digital convertor. These connect to the Pi zero via the !2C bus and the SPI interface. I would like to replace the Pi zero with the nRF9160 dev board, can some one point me to some example hw and sw that will enable me to quickly convert. Thanks, Rod

Parents Reply
  • Jan, thank you for your reply. A couple  of follow on questions.
    1. Am I correct in saying that I can assign any GPIO pins as SPI and I2C interfaces?
    2. As part of my development process, I want to phase in the replacement of the Raspberry Pi. In the next version on the prototype, I would like to keep the Pi zero and add the nRF9160DK effectively as a peripheral. 
    So, please can you advise how I can add the nRF9160DK as a peripheral to the Pi. Do I just connect over UART or can you suggest a better way?
Children
    1. In general, yes, any GPIO can be used. Some pins have dedicated functionality on the dev kit which is shown in a table on the back of the kit, so you might want to avoid them as a convenience, but they’re usable if you need them.

    2. UART, I2C, SPI etc should work fine. Note that some peripherals share the same addresses, as shown by having the same peripheral ID in this table, so that needs to be kept in mind:
      https://www.nordicsemi.com/DocLib/Content/Product_Spec/nRF9160/latest/memory#topic
  • Did you get the SPI to function on the nRF9160 I have done the setup and ried running a version of the sample code.  I do get a device pointer back, but when I try to write to the SPI device I do not see any activity on the pins, I am looking fro the clock signal as a first step the I would connect a AT25SF041-SSHD flash memory chip for testing.  Also I was not seeing in the sample code where the chip select lins was asserted.

  • Hi Jeff,

    I see that you have made a new case regarding this, great!
    We will follow up your issue there.

  • Hi Jan,

    Finally I have had the opportunity to get back to this. (Im doing this work as a side line!) Anyway, I have Zephyr now running on the board and have verified my tool chain with the standard hello World example. Next, I want to try my first sensor, the BME280. I was pleased to see there is already example code there. I added the overlay fine as you suggested above. Please can you tell me what the proper syntax is for defining the sensor. I get the error below. I guess I need to define the sensor either in my config or overlay file? Sorry, I appreciate this is quite basic stuff, Im a h/w guy in a s/w world!

    Watts-MacBook-Pro:build Watt$ ninja

    [102/109] Building C object zephyr/drivers/sensor/bme280/CMakeFiles/drivers__sensor__bme280.dir/bme280.c.obj

    FAILED: zephyr/drivers/sensor/bme280/CMakeFiles/drivers__sensor__bme280.dir/bme280.c.obj 

    ccache /Users/Watt/gnuarmemb/bin/arm-none-eabi-gcc -DBUILD_VERSION=v1.14.0-rc1-1246-g959abdf1c9c9 -DKERNEL -DNRF9160_XXAA -D_FORTIFY_SOURCE=2 -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I../../../../kernel/include -I../../../../arch/arm/include -I../../../../include -I../../../../include/drivers -Izephyr/include/generated -I../../../../soc/arm/nordic_nrf/nrf91 -I../../../../soc/arm/nordic_nrf/include -I../../../../lib/libc/minimal/include -I../../../../ext/hal/cmsis/Include -I../../../../ext/hal/nordic/nrfx -I../../../../ext/hal/nordic/nrfx/drivers/include -I../../../../ext/hal/nordic/nrfx/hal -I../../../../ext/hal/nordic/nrfx/mdk -I../../../../ext/hal/nordic/. -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include-fixed -Os -nostdinc -g -Wall -Wformat -Wformat-security -Wno-format-zero-length -imacros /Users/Watt/zephyrproject/zephyr/samples/sensor/bme280/build/zephyr/include/generated/autoconf.h -ffreestanding -Wno-main -fno-common -mthumb -mcpu=cortex-m33 -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -Wno-pointer-sign -Wno-unused-but-set-variable -fno-reorder-functions -fno-defer-pop -Werror=implicit-int -Wpointer-arith -ffunction-sections -fdata-sections -mabi=aapcs -march=armv8-m.main+dsp -std=c99 -MD -MT zephyr/drivers/sensor/bme280/CMakeFiles/drivers__sensor__bme280.dir/bme280.c.obj -MF zephyr/drivers/sensor/bme280/CMakeFiles/drivers__sensor__bme280.dir/bme280.c.obj.d -o zephyr/drivers/sensor/bme280/CMakeFiles/drivers__sensor__bme280.dir/bme280.c.obj   -c /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c

    In file included from /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c:24:0:

    /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.h:111:2: error: #error "BME280 device type not specified"

     #error "BME280 device type not specified"

      ^~~~~

    /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c: In function 'bme280_init':

    /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c:357:22: warning: unused variable 'data' [-Wunused-variable]

      struct bme280_data *data = dev->driver_data;

                          ^~~~

    In file included from ../../../../include/sensor.h:23:0,

                     from /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c:11:

    /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c: At top level:

    /Users/Watt/zephyrproject/zephyr/drivers/sensor/bme280/bme280.c:385:29: error: 'DT_BOSCH_BME280_0_LABEL' undeclared here (not in a function); did you mean 'DT_FLASH_AREA_0_LABEL'?

     DEVICE_AND_API_INIT(bme280, DT_BOSCH_BME280_0_LABEL, bme280_init, &bme280_data,

                                 ^

    ../../../../include/device.h:107:11: note: in definition of macro 'DEVICE_AND_API_INIT'

       .name = drv_name, .init = (init_fn),     \

               ^~~~~~~~

    ninja: build stopped: subcommand failed.

  • Hi,

    It looks like what you're seeing here is because the BME280 is not set up to be attached to one of your serial buses. The BME280 driver is configured to use automatically generated information from the device tree to determine which serial bus and other HW configuration to use. Every macro starting with `DT_` originates from the device tree, meaning .dts and .overlay files. So, the device tree needs to contain information about BME280. That's done by adding it to your .overlay file (named the same as your board). If you have BME280 on the I2C bus, it would look like this:

    &i2c2 {
        /* Your bus configuration goes here */
    
        /* The I2C address could be one of two, here 0x76 is assumed */
    	bme280@76 {
    		compatible = "bosch,bme280";
    		reg = <0x76>;
    		label = "BME280";
    	};
    };


    And for SPI something like this:
    &spi3 {
        /* Bus configuration here */
    
    	bme280@0 {
    		compatible = "bosch,bme280";
    		reg = <0>;
    		spi-max-frequency = <8000000>;
    		label = "BME280";
    	};
    };

    Hopefully that would get you started.

    Best regards,

    Jan Tore

Related