SD Card Read and Write Concept

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

SD Card Read and Write Concept

636 Views
Dileep1441
Contributor I

Hi,

I want read and write the SD Card in S32K144 MCU, please share the example code(until now i used can_pal_S32k144, adc_pal_S32k144) so please share the similar example code for SD Card read and write.

 

Software:S32 Design Studio for ARM Version: 2018.R1

MCU:S32K144

 

Thanks in Advance.

0 Kudos
Reply
3 Replies

614 Views
Dileep1441
Contributor I

Hello,

Can anyone give some response to my previous post with an SDCARD Read and Write Example code over the SPI in S32K144EVB.

0 Kudos
Reply

566 Views
yu1
Contributor I

 

void WriteSignleBlock(void) // 写单块操作
{
LPSPI_DRV_MasterTransfer(SEND, CMD24, NULL, 6);//发送CMD24
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));//等待spi空闲
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);// 发送两个时钟读取返回值
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, WSBF, NULL, 1); //发送写标志位
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
for(a=0;a<512;a++) //发送512个字节数据
{
LPSPI_DRV_MasterTransfer(SEND,&write_512byte[a], NULL, 1);//
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
}
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1); // 发送两个CRC校验码
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
for(i=0;i<6;i++)
{
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
}
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
}

void ReadSignleBlock(void) // 读单块操作
{
LPSPI_DRV_MasterTransfer(SEND, CMD17, NULL, 6);//发送CMD17 读单块操作
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);//发送两个时钟读取返回值
do{
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
}while(slaveDataReceive!=0xfe); //读取读标志位

for(a=0;a<512;a++) //读512个字节数据
{
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
read_512byte[a] = slaveDataReceive;
}
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);//两个CRC校验码
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
LPSPI_DRV_MasterTransfer(SEND, CMD12, NULL, 6);//发送CMD12 停止读操作
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
for(i=0;i<6;i++)
{
LPSPI_DRV_MasterTransfer(SEND, &slaveDataSend, &slaveDataReceive, 1);
while(LPSPI_DRV_MasterGetTransferStatus(SEND,&STATUS));
}
}

0 Kudos
Reply

557 Views
Dileep1441
Contributor I

Hi @yu1, or anyone,

Thanks for the reply

 

Can you please share the File Creation,Write and Read functionalities code in SDCARD with S32KA144

0 Kudos
Reply