S32K146 SD card driver with FATfs file system

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

S32K146 SD card driver with FATfs file system

974 Views
Arjun47
Contributor I

Dear Sir,

 

 I am getting my command response some time ok and most of the time wrong.

My timing for LPSPI are accurate and checked on CRO following is my send command routine please check and suggest me any changes

//------------------- send command ---------------------

int MSD0_send_command(unsigned char cmd, unsigned int arg, unsigned char crc) {
unsigned char r1,n;
unsigned char retry;

/* Dummy byte and chip enable */
CS_LOW;
// MSD0_spi_read_write(DUMMY_BYTE);
// CS_HIGH;
// MSD0_card_enable();

/* Command, argument and crc */
// CS_LOW;

if (cmd & 0x80) { /* Send a CMD55 prior to ACMD<n> */
cmd &= 0x7F;
r1 = MSD0_send_command(CMD55, 0, 0); /* should be return 0x01 */
if (r1 > 1) return r1;
}

/* Select the card and wait for ready except to stop multiple block read */
if (cmd != CMD12) {
deselect();
if (!select()) return 0xFF;
}

MSD0_spi_read_write(cmd | 0x40);
MSD0_spi_read_write(arg >> 24);
MSD0_spi_read_write(arg >> 16);
MSD0_spi_read_write(arg >> 8);
MSD0_spi_read_write(arg);
if((cmd != CMD0) || (cmd != CMD8))
MSD0_spi_read_write(crc);
else
MSD0_spi_read_write(0x01);
// CS_HIGH;


/* Wait response, quit till timeout */
for (retry = 0; retry < 200; retry++) {
r1 = MSD0_spi_read_write(DUMMY_BYTE);
if (r1 != 0xFF) {

break;
}
}
// do {
// r1 = MSD0_spi_read_write(0xFF);
// } while ((r1 & 0x80) && --n);
// CS_HIGH;
//MSD0_spi_read_write(0xa6);
/* Chip disable and dummy byte */
//MSD0_card_disable();
// CS_LOW;
// MSD0_spi_read_write(DUMMY_BYTE);
CS_HIGH;
return r1;
}

//------------------- send command ---------------------

 

Arjun K

0 Kudos
Reply
2 Replies

733 Views
P007
Contributor II
Hi @Arjun47 I am working same is your code is working fine.
If working, if you don't have any issue can pls share it with me
0 Kudos
Reply

950 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi

if a response get is sometimes correct, sometimes not, maybe it is due to SPI format setting, bitrate or pad setting issue. Did you try to decrease bitrate to know if it helps.
Did you measure SPI lines to know there are expected data? 

BR, Petr

0 Kudos
Reply