The data loss of SPI on DUE board

Hi , I am the rookie of the arduino due user.
I have the project that need to build the SPI between the Artix-7 FPGA and the arduino due.
The master is FPGA ,and the slave is due.
I find the problem that if the FPGA transmit the data through the MOSI to due continuously , the data loss would happened.
I set the SCLK is 500KHz, and the mode is 0. I use interrupt to catch the data, which I found on the Internet.
How can I solve the problem?

void setup() {
  Serial.begin(115200);
  while (!Serial);

  //SPI serial recieve
  REG_PMC_PCER0 |= PMC_PCER0_PID24;   // Power up SPI clock
  REG_SPI0_WPMR = 0 << SPI_WPMR_WPEN; //Unlock user interface for SPI

  //Instance SPI0, MISO: PA25, (MISO), MOSI: PA26, (MOSI), SCLK: PA27, (SCLK), NSS: PA28, (NPCS0)
  REG_PIOA_ABSR &= ~PIO_ABSR_P25;     // Transfer Pin control from PIO to SPI
  REG_PIOA_PDR |= PIO_PDR_P25;      // disable pio to control this pin (MOSI)

  REG_PIOA_ABSR &= ~PIO_ABSR_P26;     // Transfer Pin control from PIO to SPI
  REG_PIOA_PDR |= PIO_PDR_P26;      // disable pio to control this pin (MOSI)

  REG_PIOA_ABSR &= ~PIO_ABSR_P27;     // Transfer Pin control from PIO to SPI
  REG_PIOA_PDR |= PIO_PDR_P27;      // disable pio to control this pin (SCLK)

  REG_PIOA_ABSR &= ~PIO_ABSR_P28;     // Transfer Pin control from PIO to SPI
  REG_PIOA_PDR |= PIO_PDR_P28;      //disable pio to control this pin (NSS)

  REG_SPI0_CR = 1;            // Enable SPI
  REG_SPI0_MR = 0;            // Slave mode

  SPI0->SPI_IER = SPI_IER_RDRF;     // Receive Data Register Full Interrupt
  NVIC_EnableIRQ(SPI0_IRQn);

  REG_SPI0_CSR &= ~SPI_CSR_CPOL;  //mode 0
  SPI0->SPI_CSR[0] = SPI_CSR_NCPHA | SPI_CSR_BITS_8_BIT; // Shift on falling edge and transfer 8 bits.
  Serial.println("START");
}

bool flag = false;
uint8_t DataReceived;
//int DataReceived[31];
void SPI0_Handler()
{
  uint32_t status = SPI0->SPI_SR;
  if (status & SPI_SR_RDRF) {
    DataReceived = SPI0->SPI_RDR & SPI_RDR_RD_Msk;
    flag = true;
  }
  if (status & SPI_SR_TDRE) {
    SPI0->SPI_TDR = (uint16_t)DataReceived;
  }
}

void loop() {
  if (flag) {
    flag = false;
    Serial.println(DataReceived, HEX);

  }
}

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

Sorry for my careless

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.