This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52840 SPI slave configuration event_handler

I use zephyr to do a spi communication on nrf52840, and my nrf52840 is spi slvae

I refer to the example of zephyr spi\zephyr\tests\drivers\spi\spi_loopback\src\spi.c
At present they all use simple spi_write/spi_read to read/write spi buffer
And in zephyr\include\drivers\spi.h the rx/tx buffer is transmitted by spi_transceive
However, in the spis sample of nordic, when the slave receives the transmission data from the master, it will send it to spis_event_handler
Determine if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) in which to determine whether the transmission has been completed

On Zephyr, there is no clear example of spis event handler, most of them use while to read and write in turn
Where does zephyr judge the spis is received, and where to reach the event handler?
Also in \zephyr\drivers\spi\spi_nrfx_spi.c, I saw a function that does the same thing as the spis_event_handler of the Nordic example, as follows

static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context)
{
struct spi_nrfx_data *dev_data = p_context;

if (p_event->type == NRFX_SPI_EVENT_DONE) {
spi_context_update_tx(&dev_data->ctx, 1, dev_data->chunk_len);
spi_context_update_rx(&dev_data->ctx, 1, dev_data->chunk_len);

transfer_next_chunk(dev_data->dev);
}
}

How can I add an event handler to my main function so that after my SPI master sends data, I can find out in the event handler?

If anyone has ideas on how to fix this issue I would greatly appreciate it.

Many thanks

Parents Reply
  • Hello
    Set as follows in my proj.conf

    CONFIG_DEBUG=y
    
    CONFIG_GPIO=y
    
    CONFIG_SPI=y
    CONFIG_SPI_NRFX=y
    
    CONFIG_SPI_SLAVE=y
    CONFIG_SPI_0=y
    
    CONFIG_SPI_0_OP_MODES=2
    
    CONFIG_SPI_0_NRF_ORC=0xff
    CONFIG_NRFX_SPIS0=y

    I also printk in the event_handler of spi_nrfx_spis.c to confirm whether this function will be reached
    The result will be
    How can I reference this event_handler in my main code?
    So that I can provide semaphore in the event handler

    thanks,

    Poyi

Children
Related