Hi,
I am using nrf52832 board and I want to configure the SPI0 and SPI1 for the sensors LIS2DW and BMP388 respectively.
I am new to nRF Connect SDK for VS code, I am exploring multiple Nordic website and following the steps.
Added configuration in the proj.conf file
# Enable Kconfigs for SPI and GPIO CONFIG_GPIO=y CONFIG_SPI=y
I have created a overlay file in my project to create a node for SPI and updated the pin configuration accordingly as below. Let me know is my configuration is correct.
pedo_sensor_spi: &spi1 { compatible = "nordic,nrf-spi"; status = "okay"; pinctrl-0 = <&spi1_default>; pinctrl-1 = <&spi1_sleep>; pinctrl-names = "default", "sleep"; cs-gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>; lis2dw: lis2dw@0{ compatible = "st,lis2dw12"; reg = <0>; /* What is the actual reg value should be? */ spi-max-frequency = <125000>; /* how to decide the frequency here? */ }; }; /* Change the pin configurations */ &pinctrl { spi1_default: spi1_default { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 2)>, <NRF_PSEL(SPIM_MOSI, 0, 28)>, <NRF_PSEL(SPIM_MISO, 0, 30)>; }; }; spi1_sleep: spi1_sleep { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 2)>, <NRF_PSEL(SPIM_MOSI, 0, 28)>, <NRF_PSEL(SPIM_MISO, 0, 30)>; low-power-enable; }; }; }; bmp388_sensor_spi: &spi0 { compatible = "nordic,nrf-spi"; //using SPI as per ERRATA 58 status = "okay"; pinctrl-0 = <&spi0_default>; pinctrl-1 = <&spi0_sleep>; pinctrl-names = "default", "sleep"; cs-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; bmp388: bmp388@0{ compatible = "bosch,bmp388"; reg = <0>; /* What is the actual reg value should be? */ spi-max-frequency = <125000>; /* how to decide the frequency here? */ }; }; /* Change the pin configurations */ &pinctrl { spi0_default: spi0_default { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 15)>, <NRF_PSEL(SPIM_MOSI, 0, 22)>, <NRF_PSEL(SPIM_MISO, 0, 14)>; }; }; spi0_sleep: spi0_sleep { group1 { psels = <NRF_PSEL(SPIM_SCK, 0, 15)>, <NRF_PSEL(SPIM_MOSI, 0, 22)>, <NRF_PSEL(SPIM_MISO, 0, 14)>; low-power-enable; }; }; };
#define SPI1_PEDO SPI_WORD_SET(8) | SPI_TRANSFER_MSB struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
void spi_init (void) { int err; err = spi_is_ready_dt(&pedo_spispec); if (!err) { LOG_ERR("Error: SPI device is not ready, err: %d", err); } }
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
132 | #define _DO_CONCAT(x, y) x ## y
| ^
C:/ncs/v2.5.2/zephyr/include/zephyr/device.h:85:33: note: in expansion of macro '_CONCAT'
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/device.h:211:37: note: in expansion of macro 'DEVICE_NAME_GET'
211 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/device.h:228:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
228 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:385:24: note: in expansion of macro 'DEVICE_DT_GET'
385 | .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
| ^~~~~~~~~~~~~
../src/Application/pedometer_LIS2D.c:12:35: note: in expansion of macro 'SPI_DT_SPEC_GET'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~~~~
In file included from C:/ncs/v2.5.2/zephyr/include/zephyr/arch/arm/aarch32/arch.h:20,
from C:/ncs/v2.5.2/zephyr/include/zephyr/arch/cpu.h:19,
from C:/ncs/v2.5.2/zephyr/include/zephyr/kernel_includes.h:33,
from C:/ncs/v2.5.2/zephyr/include/zephyr/kernel.h:17,
from C:/ncs/v2.5.2/zephyr/include/zephyr/net/buf.h:16,
from C:/ncs/v2.5.2/zephyr/include/zephyr/bluetooth/bluetooth.h:25,
from ../src/Application/app_init.h:10:
zephyr/include/generated/devicetree_generated.h:11486:40: error: 'DT_N_S_soc_S_spi_40004000_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40004000_P_max_frequency'?
11486 | #define DT_N_NODELABEL_pedo_sensor_spi DT_N_S_soc_S_spi_40004000
| ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:332:30: note: in expansion of macro 'DT_PROP'
332 | .frequency = DT_PROP(node_id, spi_max_frequency), \
| ^~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
386 | .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
| ^~~~~~~~~~~~~
../src/Application/pedometer_LIS2D.c:12:35: note: in expansion of macro 'SPI_DT_SPEC_GET'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_pedo_sensor_spi'
4229 | #define DT_CAT(a1, a2) a1 ## a2
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
| ^~~~~~
../src/Application/pedometer_LIS2D.c:12:51: note: in expansion of macro 'DT_NODELABEL'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~
zephyr/include/generated/devicetree_generated.h:11486:40: error: 'DT_N_S_soc_S_spi_40004000_P_duplex' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40004000_P_reg'?
11486 | #define DT_N_NODELABEL_pedo_sensor_spi DT_N_S_soc_S_spi_40004000
| ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:334:25: note: in expansion of macro 'DT_PROP'
334 | DT_PROP(node_id, duplex) | \
| ^~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
386 | .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
| ^~~~~~~~~~~~~
../src/Application/pedometer_LIS2D.c:12:35: note: in expansion of macro 'SPI_DT_SPEC_GET'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_pedo_sensor_spi'
4229 | #define DT_CAT(a1, a2) a1 ## a2
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
| ^~~~~~
../src/Application/pedometer_LIS2D.c:12:51: note: in expansion of macro 'DT_NODELABEL'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~
zephyr/include/generated/devicetree_generated.h:11486:40: error: 'DT_N_S_soc_S_spi_40004000_P_frame_format' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40004000_P_interrupts'?
11486 | #define DT_N_NODELABEL_pedo_sensor_spi DT_N_S_soc_S_spi_40004000
| ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:335:25: note: in expansion of macro 'DT_PROP'
335 | DT_PROP(node_id, frame_format), \
| ^~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
386 | .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
| ^~~~~~~~~~~~~
../src/Application/pedometer_LIS2D.c:12:35: note: in expansion of macro 'SPI_DT_SPEC_GET'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_pedo_sensor_spi'
4229 | #define DT_CAT(a1, a2) a1 ## a2
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
| ^~~~~~
../src/Application/pedometer_LIS2D.c:12:51: note: in expansion of macro 'DT_NODELABEL'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~
In file included from C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:19:
zephyr/include/generated/devicetree_generated.h:11491:57: warning: unsigned conversion from 'int' to 'short unsigned int' changes value from '1073758208' to '16384' [-Woverflow]
11491 | #define DT_N_S_soc_S_spi_40004000_REG_IDX_0_VAL_ADDRESS 1073758208 /* 0x40004000 */
| ^~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4233:33: note: in expansion of macro 'DT_N_S_soc_S_spi_40004000_REG_IDX_0_VAL_ADDRESS'
4233 | #define DT_CAT4(a1, a2, a3, a4) a1 ## a2 ## a3 ## a4
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:2201:9: note: in expansion of macro 'DT_CAT4'
2201 | DT_CAT4(node_id, _REG_IDX_, idx, _VAL_ADDRESS)
| ^~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:2224:30: note: in expansion of macro 'DT_REG_ADDR_BY_IDX'
2224 | #define DT_REG_ADDR(node_id) DT_REG_ADDR_BY_IDX(node_id, 0)
| ^~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:336:26: note: in expansion of macro 'DT_REG_ADDR'
336 | .slave = DT_REG_ADDR(node_id), \
| ^~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
386 | .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
| ^~~~~~~~~~~~~
../src/Application/pedometer_LIS2D.c:12:35: note: in expansion of macro 'SPI_DT_SPEC_GET'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~~~~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_pedo_sensor_spi'
4229 | #define DT_CAT(a1, a2) a1 ## a2
| ^~
C:/ncs/v2.5.2/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
| ^~~~~~
../src/Application/pedometer_LIS2D.c:12:51: note: in expansion of macro 'DT_NODELABEL'
12 | struct spi_dt_spec pedo_spispec = SPI_DT_SPEC_GET(DT_NODELABEL(pedo_sensor_spi),SPI1_PEDO,0);
| ^~~~~~~~~~~~
[27/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/notify.c.obj
[28/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/assert.c.obj
[29/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/mpsc_pbuf.c.obj
[30/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/reboot.c.obj
[31/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/multi_heap.c.obj
[32/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/timeutil.c.obj
[33/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/cbprintf_complete.c.obj
[34/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/heap-validate.c.obj
[35/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/thread_entry.c.obj
[36/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/heap.c.obj
[37/194] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/nordic_nrf/validate_base_addresses.c.obj
[38/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/onoff.c.obj
[39/194] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/bitarray.c.obj
ninja: build stopped: subcommand failed.