nrf52dk not able to build the SPI project.

Hello,

We are using nrf52dk, with zephyr OS also we have done the setup in VS code with extension.

Toolchain version: v2.9.0

SDK version: 3.7.99-ncs2, these all came in extension of nrf connect in vs code.

Expectation: We need to communicate the sensor over SPI1 with MAX30001 device.

Problem: I am not able to build the project. getting error of SPI node.

Build error logs:

//
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\b620d30767\opt\bin\cmake.EXE' --build C:/nrf52/my_sample/sample_SPI/build

Can anyone please help me on this. As I am new on this. Please guide us how to solve this issue.

Parents
  • #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/spi.h>
    
    static const struct spi_dt_spec spi1_spec = SPI_DT_SPEC_GET(
        DT_NODELABEL(reg_my_spi_master),  // Device tree node label
        SPI_WORD_SET(8),                  // 8-bit word size
        0                                 // CS release delay
    );
    
    static void readRegister()
    {
    	int err;
    	uint8_t chip_id[3];
    	uint8_t spiTxCommand[1];
    	spiTxCommand[0] = ((0x0F << 1) | 0x01);
    
    	const struct spi_buf tx_buf = {
    		.buf = &spiTxCommand,
    		.len = sizeof(spiTxCommand)
    	};
    
        const struct spi_buf_set tx = {
    		.buffers = &tx_buf,
    		.count = 1
    	};
    
        struct spi_buf rx_buf[2] = {
    		{
    			.buf = NULL,
    			.len = 1
    		},
    		{
    			.buf = chip_id,
    			.len = 3
    		}
    	}; // 24 bit register + 1 dummy byte
        
    	const struct spi_buf_set rx = {
    		.buffers = rx_buf,
    		.count = 2
    	};
    	
    	do
    	{
    		err = spi_transceive_dt(&spi1_spec, &tx, &rx);
    		if (err  < 0) { break; }
    
    	} while (false);
    
    	printk("MAX30001 ID: 0x%02X 0x%02X 0x%02X\n", (uint8_t)chip_id[0], (uint8_t)chip_id[1], (uint8_t)chip_id[2]);
    }
    
    
    int main(void)
    {
    	if (!spi_is_ready_dt(&spi1_spec)) {
    		printf("SPI1 DEV NOT READY\n");
    		return 0;
    	}
    
    	readRegister();
    
    	while (1) {
    		readRegister();
    		k_msleep(1000);
    	}
    	return 0;
    }

Reply
  • #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/spi.h>
    
    static const struct spi_dt_spec spi1_spec = SPI_DT_SPEC_GET(
        DT_NODELABEL(reg_my_spi_master),  // Device tree node label
        SPI_WORD_SET(8),                  // 8-bit word size
        0                                 // CS release delay
    );
    
    static void readRegister()
    {
    	int err;
    	uint8_t chip_id[3];
    	uint8_t spiTxCommand[1];
    	spiTxCommand[0] = ((0x0F << 1) | 0x01);
    
    	const struct spi_buf tx_buf = {
    		.buf = &spiTxCommand,
    		.len = sizeof(spiTxCommand)
    	};
    
        const struct spi_buf_set tx = {
    		.buffers = &tx_buf,
    		.count = 1
    	};
    
        struct spi_buf rx_buf[2] = {
    		{
    			.buf = NULL,
    			.len = 1
    		},
    		{
    			.buf = chip_id,
    			.len = 3
    		}
    	}; // 24 bit register + 1 dummy byte
        
    	const struct spi_buf_set rx = {
    		.buffers = rx_buf,
    		.count = 2
    	};
    	
    	do
    	{
    		err = spi_transceive_dt(&spi1_spec, &tx, &rx);
    		if (err  < 0) { break; }
    
    	} while (false);
    
    	printk("MAX30001 ID: 0x%02X 0x%02X 0x%02X\n", (uint8_t)chip_id[0], (uint8_t)chip_id[1], (uint8_t)chip_id[2]);
    }
    
    
    int main(void)
    {
    	if (!spi_is_ready_dt(&spi1_spec)) {
    		printf("SPI1 DEV NOT READY\n");
    		return 0;
    	}
    
    	readRegister();
    
    	while (1) {
    		readRegister();
    		k_msleep(1000);
    	}
    	return 0;
    }

Children
No Data
Related