guillaume dournes

Transmission SPI in slave mode buffered ?

Discussion created by guillaume dournes on Oct 14, 2009
Latest reply on Oct 15, 2009 by Pedro Palacios

Hi,

 

I'm using a MC9HS12XEP100.

I want to receive and transmit some data on a SPI.

My SPI is in slave mode, 16bits mode with SS/.

When I receive one word, I want to transmit an other word.

 

There is no problem on the reception, but the transmission seems to be delayed, as there is a transmission buffer of 2 words.

 

Whereas the SPI2DR register is set to 0x1111 for exemple, the 2 first word transmitted are 0x000, and the third is 0x1111.

 

I want to transmit :

0x1111

0x2222

0x3333

0x4444

0x1111

0x2222

....

 

But in fact the transmission is :

0x0000

0x0000

0x1111

0x2222

0x3333

0x4444

0x1111

....

 

Is the 2 words transmission buffer  configurable. How can i deactivate it, or how can I force this value ?

 

 

 

My interupt code :

//------------------------------------------------------------------------------
//  SPI2 interrupt
//------------------------------------------------------------------------------
ISR(CPU12SPI2SR)
{
  UINT16 u16RxBuffer = 0;
 
  //DEBUG
  //PORTK |= 0x01;
 
  if (SPI2SR & SPI2SR_SPIF_MASK)
  //if (SPI2SR & SPI2SR_SPTEF_MASK)
  {
    //DEBUG
    //PORTK |= 0x02;
   
    // Read
    u16RxBuffer = SPI2DR;
    if ((u16RxBuffer) && (bSPI2_ACTT_Enable == TRUE))
    {
      TransmissionSCIPC_SPIR(1, u16RxBuffer);
    }
    // Transmit a word from the SPIT buffer
    if (u8SPIT_Counter_Buffer > 3)
    {
      u8SPIT_Counter_Buffer = 0;
    }
    SPI2DR = u16SPIT_Buffer[u8SPIT_Counter_Buffer++];
  }
  else if (SPI2SR & SPI2SR_SPTEF_MASK)
  {
   
   
    // Transmit a word from the SPIT buffer
    if (u8SPIT_Counter_Buffer > 3)
    {
      u8SPIT_Counter_Buffer = 0;
    }
    SPI2DR = u16SPIT_Buffer[u8SPIT_Counter_Buffer++];
  }
}

Outcomes