Jared McIntyre

Force update SPI tx shift register

Discussion created by Jared McIntyre on May 9, 2016
Latest reply on Apr 10, 2018 by Hui_Ma

I'm experimenting with the SPI slave implementation on the K20 series by implementing a simple echo protocol. Master sends a word and the slave returns it immediately. The double buffered nature of the shift register is getting in my way. I've posted a simplified version of my interrupt handler below.

 

The problem is that when I push the value onto SPI0_PUSHR_SLAVE, whatever is in the shift register is pushed out. In order to have the frame immediately following the command contain the value of the command, I need to invalidate that shift register so that it will send out the value I just pushed on. I can't seem to find a mechanism to do this.

 

void spi0_isr(void)

{  

  if( false == writing )

  {

    uint8_t response;

    response = SPI0_POPR;

    writing = true;

    SPI0_PUSHR_SLAVE = response;

    SPI0_SR |= SPI_SR_RFDF;

  }

  else

  {

    uint8_t throw_away;

    throw_away = SPI0_POPR;

    SPI0_SR |= SPI_SR_RFDF;

    writing = false;

    command_phase = true;

  }

}

Outcomes