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.SendBuf Library Routine
This is the original NXP Send:
static BOOL SendBuf (U8 *buf, U32 sz) {
/* Send buffer to SPI interface. */
U32 i;
for (i = 0; i < sz; i++) {
SSPDR = buf[i];
/* Wait if Tx FIFO is full. */
while (!(SSPSR & TNF));
SSPDR;
}
/* Wait until Tx finished, drain Rx FIFO. */
while (SSPSR & (BSY | RNE)) {
SSPDR;
}
return (__TRUE);
}
This my first trial for the Kinetis SendBuf:
/*--------------------------- SendBuf ---------------------------------------*/
static BOOL SendBuf (U8 *buf, U32 sz)
{/* Send buffer to SPI interface. */
U32 i;
for (i = 0; i < sz; i++)
{
SPI2->PUSHR = (SPI_PUSHR_PCS(2) || buf[i]);
while ((SPI2->SR & SPI_SR_TFFF_MASK) == 0) {};
while ((SPI2->SR & SPI_SR_RFDF_MASK) == 0) {};
}
SPI2->SR = (SPI_SR_TFFF_MASK || (SPI2->SR & SPI_SR_RFDF_MASK));
return (__TRUE);
}
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