SPI with SDHC card issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI with SDHC card issue

611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by aamir ali on Thu Dec 13 04:45:40 MST 2012
I have to send 512 bytes on SDHC card.I am using below code for it. Is it necessary to check TFE & RNE in code.

1. I think there is no need for TFE because next to it is bsy flag, which check for TxFIFO empty or not also.

2. But is thete any need for RNE flag also. I don't want to know what's the coming byte. I have to just send the bytes.
However, I guess not checking for RNE flag could cause overflow of RxFIFO or can create problem.Or

BSY flag takes care of it also.


uint8_t SPI_Byte( uint8_t ThisByte )
{
//while( (LPC_SSP0->SR & 0x01) !=0x01 );     //TFE   
while( (LPC_SSP0->SR & 0x10) !=0 );          // BSY    
LPC_SSP0->DR = ThisByte; 
while( (LPC_SSP0->SR & 0x04) != 0x04);         //RNE
//while( (LPC_SSP0->SR & 0x10) !=0 );        //BSY
return( LPC_SSP0->DR ); 
}
0 Kudos
Reply
1 Reply

598 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Dec 13 20:20:42 MST 2012

Quote: Aamir Ali
I have to send 512 bytes on SDHC card.I am using below code for it. Is it necessary to check TFE & RNE in code.

1. I think there is no need for TFE because next to it is bsy flag, which check for TxFIFO empty or not also.

2. But is thete any need for RNE flag also. I don't want to know what's the coming byte. I have to just send the bytes.
However, I guess not checking for RNE flag could cause overflow of RxFIFO or can create problem.Or

BSY flag takes care of it also.


uint8_t SPI_Byte( uint8_t ThisByte )
{
//    while( (LPC_SSP0->SR & 0x01) !=0x01 );     //TFE   
    while( (LPC_SSP0->SR & 0x10) !=0 );          // BSY    
    LPC_SSP0->DR = ThisByte; 
    while( (LPC_SSP0->SR & 0x04) != 0x04);         //RNE
//    while( (LPC_SSP0->SR & 0x10) !=0 );        //BSY
    return( LPC_SSP0->DR ); 
}



Yes , It is necessary to check TFE, RNE and BSY.
TFE--> Transmit FIFO Empty. This bit is 1 is the Transmit FIFO is empty, 0 is not. Reset Value is 1.
RNE--> Receive FIFO Not Empty. This bit is 0 if the Receive FIFO is empty, 1 if not.
Reset Value is 0.
BSY--> Busy, This bit is 0 if the SPI controller is idle, 1 if it is currently sending/receiving a frame and/or the TxFIFO is not Empty.
Reset Value is 0.
0 Kudos
Reply