Sample program to use asynchronous SPI

Hi,

I need to know on how to work with asynchronous SPI for my application use case evaluation, However i found no sample/example projects demonstrating the use of nCS API

static inline int spi_transceive_async(const struct device *dev,
				       const struct spi_config *config,
				       const struct spi_buf_set *tx_bufs,
				       const struct spi_buf_set *rx_bufs,
				       struct k_poll_signal *async)

Kindly point me to any example where use of "spi_transceive_async" has been demonstrated.
I am using nRF52833

Parents Reply Children
  • Hi,

    You can read more about SPI on our documentation pages - SPISPIM and SPIS.
    You can also read more about asynchronous notifications and look at test_adc example.

    Best regards,
    Dejan

  • Hello dejans,

    My app code using spi_transceive_async always returns error, The API executes successfully, post which it throws a thread error
    Can you kindly suggest where it is wrong:

    void main(void)
    {	struct k_poll_signal async_sig;
    	uint8_t data = 40, val =0, sz = 9;
    
    	    struct spi_buf bufs = {
                .buf = &data,
                .len = sizeof(data)
        };
        struct spi_buf_set tx = {
            .buffers = &bufs
        };
    
        tx.count = 1;
    
    	struct spi_buf rbufs = {
                .buf = &val,
                .len = sizeof(val)
        };
        struct spi_buf_set rx = {
            .buffers = &rbufs
        };
    
     spi_config spi_cfg;
    spi_cs_control cs_ctrl;
        cs_ctrl.gpio_dev = device_get_binding("GPIO_0");
        cs_ctrl.gpio_pin = 11;
        cs_ctrl.delay = 0;
        spi_cfg.operation = SPI_WORD_SET(8) | SPI_OP_MODE_MASTER 
        //                    | SPI_MODE_CPOL | SPI_MODE_CPHA 
                            | SPI_LINES_SINGLE; 
        spi_cfg.frequency = 1000000;
    	spi_cfg.cs = &cs_ctrl;
    
    	const device * sp;
    	sp = device_get_binding("SPI_0");
    
    		data++;
    			struct k_poll_event  async_evt =
    		K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
    					 K_POLL_MODE_NOTIFY_ONLY,
    					 &async_sig);
    
    			printk("transmitted data: %u \n", data);
    			int error = spi_transceive_async(sp,&spi_cfg,&tx, &rx,&async_sig);
    			int ret = k_poll(&async_evt, 1, K_MSEC(1000));
    			printk("received data: %u \n", val);
    
    }

    Error:

  • Hi,

    You have received an answer in this case.
    Since there is no benefit for our customers if we duplicate cases, please continue communication there.

    Best regards,
    Dejan

Related