SPI slave always returns -ETIMEDOUT

Hi,

I am working on SPI master-slave application, as in, on one BL653 I am running SPI master driver, I am able to observe the waveforms for clock and data transfer from master on USB logic analyzer.

But I am facing an issue with the BL653 board which is running SPI slave code, basically, for slave under main my code is as below:

	m_spi_cfg->operation |= SPI_WORD_SET(8);

	m_rx_bufs->buf = &data;
	m_rx_bufs->len = sizeof(data);

	m_rx_set_buff->buffers = m_rx_bufs;
	m_rx_set_buff->count = 1;

	if ((m_spi_dev) != nullptr)
	{
		l_nStatus = spi_read(m_spi_dev, m_spi_cfg, m_rx_set_buff);
		printk("Received data : %u : %d\n",data,l_nStatus);
		if (l_nStatus != SUCCESS)
		{
			return ERR;
		}
	}

Here spi_read always returns -116, that is  -ETIMEDOUT.

My device binding, spi slave configurations and wiring with spi master are in order.

But I do not understand why slave driver always returns -ETIMEDOUT.

I traced the flow of execution all the way to the source of the error and here is what I found

spi_read( ) -> transceive (in file "spi_nrfx_spis.c") -> spi_context_wait_for_completion( in file "spi_context.h") -> and the source of error is as attached in the below snap in #else part 

Without debug mode as well I am getting the same -ETIMEDOUT.

Kindly suggest on if I have missed out on configuring something.


Thanks,

Ubaid

Parents
  • Hi,

    Can you share the rest of the source code, and your prj.conf file?

    Where are you calling the spi_read() function?

    Are the CSN pin connected and toggling as expected?

    Best regards,
    Jørgen

  • Hello Jørgen,

    Thank you so much, Master's signals I am able to observe on USB logic analyzer, CLK, MOSI & CS (all three),

    as in below snap, cs stays low for 26micro secs during which master board is sending data:


    Roughly below is my slave code Jørgen, running on another board:

    #define SPI_DEVICE_NAME_P1 DT_LABEL(DT_NODELABEL(spi1))
    const device *m_spi_dev;
    struct spi_config *m_spi_cfg = new spi_config();
    void main(void)
    {
    
    	uint8_t spi_channel = 1;
    	bool is_master;
    
    	uint8_t port = 0;
    	uint8_t pin = 23;
    	uint32_t flag = GPIO_ACTIVE_LOW;//GPIO_OUTPUT_ACTIVE;
    	
        m_spi_dev = device_get_binding(SPI_DEVICE_NAME_P1);
        
        m_spi_cfg->frequency =  4000000;
        m_spi_cfg->operation |= SPI_OP_MODE_SLAVE;
        m_spi_cfg->slave = 1;
        m_spi_cfg->operation |= SPI_WORD_SET(8);
        
        const struct device	*gpio_dev = device_get_binding("GPIO_0");
        uint8_t gpio_pin_t = 23;
        uint8_t gpio_dt_flags_t = GPIO_ACTIVE_LOW;
        
        gpio_pin_configure(gpio_dev, gpio_pin_t, GPIO_INPUT | gpio_dt_flags_t);
        
        static uint8_t rx_buffer[1];
        struct spi_buf rx_buf = {
    .buf = rx_buffer,
    .len = sizeof(rx_buffer),
    };	
    
    const struct spi_buf_set rx = {
    .buffers = &rx_buf,
    .count = 1
    };
        
        while(true)
        {
        	l_nStatus = spi_read(m_spi_dev, m_spi_cfg, &rx);
    		printk("RX recv: %u : %d \n", rx_buffer[0],l_nStatus);
    		if (l_nStatus != SUCCESS)
    		{
    			return ERR;
    		}
            
        }
        
        }
        
        

    prj.conf:

    #C++ support configs
    CONFIG_CPLUSPLUS=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_LIB_CPLUSPLUS=y
    CONFIG_HEAP_MEM_POOL_SIZE=16348
    CONFIG_OPENOCD_SUPPORT=n
    
    #SPI
    CONFIG_SPI=y
    CONFIG_SPI_SLAVE=y
    CONFIG_LOG=y
    #CONFIG_SPI_ASYNC=y

    overlay:

    &spi1 {
    	compatible = "nordic,nrf-spis";
    	status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	cs-gpios = <&gpio0 23 0>;
    	csn-pin = <23>;
        def-char = <0xFF>;
    };



    Now with this code I am getting prints for:

    -ETIMEDOUT

    or 

    -EIO

    Being generated from adc_context.h

Reply
  • Hello Jørgen,

    Thank you so much, Master's signals I am able to observe on USB logic analyzer, CLK, MOSI & CS (all three),

    as in below snap, cs stays low for 26micro secs during which master board is sending data:


    Roughly below is my slave code Jørgen, running on another board:

    #define SPI_DEVICE_NAME_P1 DT_LABEL(DT_NODELABEL(spi1))
    const device *m_spi_dev;
    struct spi_config *m_spi_cfg = new spi_config();
    void main(void)
    {
    
    	uint8_t spi_channel = 1;
    	bool is_master;
    
    	uint8_t port = 0;
    	uint8_t pin = 23;
    	uint32_t flag = GPIO_ACTIVE_LOW;//GPIO_OUTPUT_ACTIVE;
    	
        m_spi_dev = device_get_binding(SPI_DEVICE_NAME_P1);
        
        m_spi_cfg->frequency =  4000000;
        m_spi_cfg->operation |= SPI_OP_MODE_SLAVE;
        m_spi_cfg->slave = 1;
        m_spi_cfg->operation |= SPI_WORD_SET(8);
        
        const struct device	*gpio_dev = device_get_binding("GPIO_0");
        uint8_t gpio_pin_t = 23;
        uint8_t gpio_dt_flags_t = GPIO_ACTIVE_LOW;
        
        gpio_pin_configure(gpio_dev, gpio_pin_t, GPIO_INPUT | gpio_dt_flags_t);
        
        static uint8_t rx_buffer[1];
        struct spi_buf rx_buf = {
    .buf = rx_buffer,
    .len = sizeof(rx_buffer),
    };	
    
    const struct spi_buf_set rx = {
    .buffers = &rx_buf,
    .count = 1
    };
        
        while(true)
        {
        	l_nStatus = spi_read(m_spi_dev, m_spi_cfg, &rx);
    		printk("RX recv: %u : %d \n", rx_buffer[0],l_nStatus);
    		if (l_nStatus != SUCCESS)
    		{
    			return ERR;
    		}
            
        }
        
        }
        
        

    prj.conf:

    #C++ support configs
    CONFIG_CPLUSPLUS=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_LIB_CPLUSPLUS=y
    CONFIG_HEAP_MEM_POOL_SIZE=16348
    CONFIG_OPENOCD_SUPPORT=n
    
    #SPI
    CONFIG_SPI=y
    CONFIG_SPI_SLAVE=y
    CONFIG_LOG=y
    #CONFIG_SPI_ASYNC=y

    overlay:

    &spi1 {
    	compatible = "nordic,nrf-spis";
    	status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	cs-gpios = <&gpio0 23 0>;
    	csn-pin = <23>;
        def-char = <0xFF>;
    };



    Now with this code I am getting prints for:

    -ETIMEDOUT

    or 

    -EIO

    Being generated from adc_context.h

Children
No Data
Related