hamsiii
Member level 2
Hello all,
We are working on Elm Chan's FF system with our MSP430F5438. We connected SD with SPI interface, modified the code for this purpose. When debugging, we have some problems, we cannot create a file, write in it or close it. When we examine through breakpoints, we have seen that disk is not initialized. The code below is proceding with "STA_NOINIT" in mmcbb.c and returns us FR_NOT_READY in "ff.c". So, the disk is not initialized.
We also set the SPI interface as below for MSP430F5438; (these codes might actually be wrong as we didnt modify this disc initialization code)
Would you please comment on our code, that tells where we could be wrong?
We are working on Elm Chan's FF system with our MSP430F5438. We connected SD with SPI interface, modified the code for this purpose. When debugging, we have some problems, we cannot create a file, write in it or close it. When we examine through breakpoints, we have seen that disk is not initialized. The code below is proceding with "STA_NOINIT" in mmcbb.c and returns us FR_NOT_READY in "ff.c". So, the disk is not initialized.
Code:
DSTATUS disk_initialize (
BYTE drv /* Physical drive number (0) */
)
{
BYTE n, ty, cmd, buf[4];
UINT tmr;
DSTATUS s;
if (drv) return RES_NOTRDY;
INIT_PORT(); /* Initialize control port */
for (n = 10; n; n--)
rcvr_mmc(buf, 1); /* 80 dummy clocks */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2? */
rcvr_mmc(buf, 4); /* Get trailing return value of R7 resp */
if (buf[2] == 0x01 && buf[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
for (tmr = 1000; tmr; tmr--) { /* Wait for leaving idle state (ACMD41 with HCS bit) */
if (send_cmd(ACMD41, 1UL << 30) == 0) break;
__delay_cycles(1000);
}
if (tmr && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
rcvr_mmc(buf, 4);
ty = (buf[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 */
}
}
} else { /* SDv1 or MMCv3 */
if (send_cmd(ACMD41, 0) <= 1) {
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
} else {
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
}
for (tmr = 1000; tmr; tmr--) { /* Wait for leaving idle state */
if (send_cmd(cmd, 0) == 0) break;
__delay_cycles(1000);
}
if (!tmr || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
ty = 0;
}
}
CardType = ty;
s = ty ? 0 : STA_NOINIT;
Stat = s;
deselect();
return s;
}
We also set the SPI interface as below for MSP430F5438; (these codes might actually be wrong as we didnt modify this disc initialization code)
Code:
#define INIT_PORT() init_port()
#define CSPORT P3OUT
#define CLKPORT P3OUT
#define DIPORT P3OUT
#define DOPORT P3OUT
#define CS 1<<3
#define CK 1<<0
#define DI 1<<4
#define DO_ 1<<5
#define CS_H() CSPORT |= CS
#define CS_L() CSPORT &= ~CS
#define CK_H() CLKPORT |= CK
#define CK_L() CLKPORT &= ~CK
#define DI_H() DIPORT |= DI
#define DI_L() DIPORT &= ~DI
#define DO DOPORT & DO_
void init_port(void)
{
CSPORT |= CS_H();
spi_init();
}
Would you please comment on our code, that tells where we could be wrong?