Hello,
4-byte long SPI messages, "1234", are sent to nRF 52DK. The code in DK is attached below. The XFER_DONE event is created before the message ends, which happens very often. I tried to change message frequency, clock frequency, and lots of things. Nothing is changed.
The below figure shows the sent SPI messages containing "1234". The toggled port is on Channel 5 when XFER_DONE is created. The corresponding received messages are shown between asterisk symbols on the figure.
I need more accurate messaging. Any suggestion?

#include "sdk_config.h"
#include "nrf_delay.h"
#include "nrf_drv_spis.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "app_error.h"
#include <string.h>
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#define SPIS_INSTANCE 1 /**< SPIS instance index. */
static const nrf_drv_spis_t spis = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/**< SPIS instance. */
static uint8_t m_tx_buf[4]; /**< TX buffer. */
static uint8_t m_rx_buf[5]; /**< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf); /**< Transfer length. */
static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
static uint8_t count = 0;
void spis_event_handler(nrf_drv_spis_event_t event){
static uint8_t count = 0;
if (event.evt_type == NRF_DRV_SPIS_XFER_DONE){
spis_xfer_done = true;
nrf_gpio_pin_toggle(3);
NRF_LOG_INFO("%d XFER: *%s*",count++,(uint32_t)m_rx_buf);
}
}
int main(void)
{
NRF_POWER->TASKS_CONSTLAT = 1;
bsp_board_init(BSP_INIT_LEDS);
nrf_gpio_cfg_output(3);
nrf_gpio_pin_write(3, 0);
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("SPIS example");
nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
spis_config.csn_pin = 28; //APP_SPIS_CS_PIN; //port 0.31
spis_config.miso_pin = 31; //APP_SPIS_MISO_PIN; //port 0.30
spis_config.mosi_pin = 30; //APP_SPIS_MOSI_PIN; //port 0.29
spis_config.sck_pin = 29; //APP_SPIS_SCK_PIN; //port 0.26
APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));
while (1){
memset(m_rx_buf, 0, m_length);
spis_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
while (!spis_xfer_done){ __WFE();}
NRF_LOG_FLUSH();
bsp_board_led_invert(BSP_BOARD_LED_0);
}
}