AnsweredAssumed Answered

Porting SPI Driver to Keil RL-ARM System: Send

Question asked by tfrauenrath on Jul 3, 2013

My task is to port a NXP SPI driver delivered with Keil RL-ARM to my Kinetis K60 system. Finlay I want to talk to SD cards in SPI mode. I do this step by step. My next task is the Send routine.

RL-ARM User's Guide: spi.Send Library Routine


This is the original NXP Send:

/* Send and receive a byte on SPI interface. */
static U8 Send (U8 outb) {

  SSPDR = outb;
  while (!(SSPSR & RNE)); /* Wait if RNE cleared, Rx FIFO is empty. */
  return (SSPDR);


This my first trial for the Kinetis Send:



/*--------------------------- Send ------------------------------------------*/
static U8 Send (U8 outb) 
{/* Write and Read a byte on SPI interface. */
unsigned char tmp;

SPI2->PUSHR = (SPI_PUSHR_PCS(2) || outb);
while ((SPI2->SR & SPI_SR_TFFF_MASK) == 0) {};
while ((SPI2->SR & SPI_SR_RFDF_MASK) == 0) {};
tmp = SPI2->POPR;
return (tmp); // return read byte    

Do you think this is applicable for SD card access via SPI?

I will discuss the other routines in other threads because of a better overview. I will post the final driver, because Keil provides only samples for SDHC mode for memory cards for the Kinetis system.


Thank you