Hi,
I would like to consult how could I deal with this error and build the code succesfully.
In device.h
'__device_dts_ord_113' undeclared here (not in a function); did you mean '__device_dts_ord_11'?
In devicetree_generated .h
'DT_N_S_soc_S_peripheral_50000000_S_spi_c7000_S_mysensor2_0_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_50000000_S_spi_4a000_S_mx25r6435f_0_P_spi_max_frequency'?
Below is my overlay file
&i2c22 { status = "okay"; pinctrl-0 = <&i2c22_default>; pinctrl-1 = <&i2c22_sleep>; pinctrl-names = "default", "sleep"; mysensor: mysensor@77 { //BME280 Test compatible = "i2c-device"; status = "okay"; reg = <0x77>; }; }; &uart21 { current-speed = <57600>; pinctrl-0 = <&uart21_default>; pinctrl-1 = <&uart21_sleep>; pinctrl-names = "default", "sleep"; }; &spi21 { compatible = "nordic,nrf-spim"; status = "okay"; pinctrl-0 = <&spi21_default>; pinctrl-1 = <&spi21_sleep>; pinctrl-names = "default", "sleep"; cs-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>; mysensor2: mysensor2@0 { compatible = "spi-device"; reg = <0>; spi-max-frequency = <1000000>; }; }; &pinctrl { /omit-if-no-ref/ i2c22_default: i2c22_default { group1 { psels = <NRF_PSEL(TWIM_SCL, 1, 11)>, <NRF_PSEL(TWIM_SDA, 1, 12)>; }; }; /omit-if-no-ref/ i2c22_sleep: i2c22_sleep { group1 { psels = <NRF_PSEL(TWIM_SCL, 1, 11)>, <NRF_PSEL(TWIM_SDA, 1, 12)>; low-power-enable; }; }; spi21_default: spi21_default { group1 { psels = <NRF_PSEL(SPIM_SCK, 1, 8)>, <NRF_PSEL(SPIM_MOSI, 1, 13)>, <NRF_PSEL(SPIM_MISO, 1, 14)>; }; }; spi21_sleep: spi21_sleep { group1 { psels = <NRF_PSEL(SPIM_SCK, 1, 8)>, <NRF_PSEL(SPIM_MOSI, 1, 13)>, <NRF_PSEL(SPIM_MISO, 1, 14)>; low-power-enable; }; }; uart21_default: uart21_default { group1 { psels = <NRF_PSEL(UART_TX, 1, 0)>, <NRF_PSEL(UART_RX, 1, 1)>; }; }; uart21_sleep: uart21_sleep { group1 { psels = <NRF_PSEL(UART_TX, 1, 0)>, <NRF_PSEL(UART_RX, 1, 1)>; }; }; }; / { zephyr,user { cts_pin-gpios = <&gpio1 3 GPIO_ACTIVE_LOW>; //CTS input rts_pin-gpios = <&gpio1 2 GPIO_ACTIVE_LOW>; //RTS output }; };
Below is the program code
#include <zephyr/types.h> #include <stddef.h> #include <errno.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> #include <zephyr/kernel.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/spi.h> #define SPI_NODE DT_NODELABEL(mysensor2) /*Retrieve the API-device structure */ #define SPIOP SPI_WORD_SET(8) | SPI_TRANSFER_MSB struct spi_dt_spec spispec = SPI_DT_SPEC_GET(SPI_NODE, SPIOP, 0); /* For spi thread */ K_THREAD_STACK_DEFINE(spi_stack_area, 1280); static k_tid_t spi_thread_id; static struct k_thread spi_thread_data; static int bme_write_reg(uint8_t reg, uint8_t value) { int err; //Delcare a tx buffer having register address and data */ uint8_t tx_buf[] = {(reg & 0x7F), value}; struct spi_buf tx_spi_buf = {.buf = tx_buf, .len = sizeof(tx_buf)}; struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_buf, .count = 1}; /* call the spi_write_dt function with SPISPEC to write buffers */ err = spi_write_dt(&spispec, &tx_spi_buf_set); if (err < 0) { LOG_ERR("spi_write_dt() failed, err %d", err); return err; } return 0; } static void spi_thread(void *p1, void *p2, void *p3) { printk("[%s]\n", __func__); while (1) { k_sleep(K_MSEC(10)); bme_write_reg(0xF2, 0x04); //CTRLHUM 0xF2 } } void spi_start(void) { printk("[%s]\n", __func__); //Check if SPI and GPIO devices are ready */ int err = spi_is_ready_dt(&spispec); if (!err) { printk("Error: SPI device is not ready, err: %d", err); } if (spi_thread_id == NULL) { spi_thread_id = k_thread_create(&spi_thread_data, spi_stack_area, K_THREAD_STACK_SIZEOF(spi_stack_area), spi_thread, NULL, NULL, NULL, 3, 0, K_NO_WAIT); int ret = k_thread_name_set(spi_thread_id, "SPI_THREAD"); if (ret) { printk("[%s], Set thread name failed = %d\n", __func__, ret); } } }
Here is the project configuration
#Add for I2C CONFIG_I2C=y #Add for UART CONFIG_SERIAL=y CONFIG_UART_ASYNC_API=y CONFIG_UART_INTERRUPT_DRIVEN=n #Add for Using inteneral RC CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y #Add for GPIO Configure CONFIG_GPIO=y CONFIG_NFCT_PINS_AS_GPIOS=y #Add for set the thread name CONFIG_THREAD_NAME=y CONFIG_THREAD_MAX_NAME_LEN=12 #Add for SPI CONFIG_SPI=y