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 Children
  • Hi,

     

    hmw said:
    What I want is to have an IRQ_Handler that allows me to give semaphore behavior when an interrupt occurs

    Then disabling the zephyr SPI driver (CONFIG_SPI*=n) and using the CONFIG_NRFX_SPIS driver directly is a possibility.

    You should not mix "spi_nrfx_spis" into the mix here, as this is the port file for the zephyr SPI driver.

     

    If you look at the nRF5 SDK example in peripheral/spis/, it has a slightly modified API (legacy API), but shows the flow of how to use the nrfx_spis driver.

    Note that you should also add CONFIG_NRFX_SPISx=y to choose which instance you want to use.

     

    Kind regards,

    Håkon 

Related