I transfer data by ESB between send and receive.
And I want to transfer 2 bytes x 10 data that is received by ESB every T[s] to ESB receive (trigger) -> PPI->SPIM, 2 bytes every T/10[s].
We have already confirmed that the hardware can correctly drive the SPI SS, SCLK and MOSI every T/10[s] starting from the ESB receive timing.
However, as it is an ESB, it can be triggered, but I understand that the passing from the ESB receive buffer to the SPI TX buffer needs to be done via the CPU (interrupt processing).
So I first prepared an ESB receive buffer 2 bytes x 10 (payload) and a SPI TX buffer 2 bytes x 1. I then increment the read address of the ESB receive buffer for each SPI interrupt and copy the 2 bytes to the SPI TX buffer.
However, with this method, the 10/10th data may not be correctly transferred to the SPI's TX buffer.
It seems that the SPI interrupt has a lower priority than the ESB receive interrupt and the 10/10th SPI interrupt is delayed, thus delaying the 10/10th data transfer and not allowing the 10/10th SPI TX operation by PPI in time.
I would therefore like to transfer the data from the ESB receive buffer to the SPI TX buffer without involving the interrupt process.
Specifically, first prepare a 2 byte x 10 SPI TX buffer, which is the same as the ESB receive buffer. Then, each time an ESB receive interrupt occurs, the 2 byte x 10 data in the ESB receive buffer is copied to the SPI TX buffer at once.
After the n-th SPI transfer, the read address of the TX buffer is incremented without an SPI interrupt to prepare for the (n+1)st SPI transfer. How can I do this?
Can you tell me how to do this specifically?
<<Current programme>>
#define SPI_DA_SIZE 2
uint8_t spi_tx_buf[ SPI_DA_SIZE ]
void spi_init(void)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = SPI_CONV;
spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.mosi_pin = SPI_MOSI;
spi_config.sck_pin = SPI_SCK;
spi_config.frequency = NRF_DRV_SPI_FREQ_4M;
spi_config.mode = NRF_DRV_SPI_MODE_2;
nrf_drv_spi_init(&SPI_0, &spi_config, spi_event_handler, NULL);
nrf_drv_spi_xfer_desc_t spi_xfer;
spi_xfer.p_tx_buffer=spi_tx_buf;
spi_xfer.tx_length=SPI_DA_SIZE;
spi_xfer.p_rx_buffer=NULL;
spi_xfer.rx_length= NULL;
nrf_drv_spi_xfer(&SPI_0,&spi_xfer,NRF_DRV_SPI_FLAG_HOLD_XFER); //It is important NRF_DRV_SPI_FLAG_HOLD_XFER.
return;
}