AnsweredAssumed Answered

Sending data on SPI using Kl25z

Question asked by Subhradeep Dutta on Mar 24, 2017
Latest reply on Mar 26, 2017 by Kerry Zhou

The data sheet for KL25z says that to clear the SPTEF bit on the SPI0_S register

 

SPTEF is cleared by reading the S register with SPTEF set and then writing a data value
to the transmit buffer at D. The S register must be read with SPTEF set to 1 before writing data to the D
register; otherwise, the D write is ignored

So does that mean that to send data over SPI I would need to wait for SPTEF to be set to 1 then write to to the data register or is another read of the status register required.

 

 

For example is the below definition sufficient

 

void SPI_write_byte(uint8_t data)
{
   while (!(SPI0_S & SPI_S_SPTEF_MASK));
   SPI0_D = data;

}

 

or do I need to do something like

 

void SPI_write_byte(uint8_t data)
{
   while (!(SPI0_S & SPI_S_SPTEF_MASK));
   SPI0_D = data;
   while (!(SPI0_S & SPI_S_SPRF_MASK));
   data = SPI0_D;
}

 

 

Also if I want to use SS pin as a manually controlled pin for slave selection and I have MODFEN = 0 and SSOE = 0, then do I just pull the Port C Pin 4 (alternate function 2) low before starting a data transfer and assert it high once the transfer is complete?

Outcomes