Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MSP430F5438 - Elm Chan code SD initialization problem

Status
Not open for further replies.

hamsiii

Member level 2
Joined
Apr 21, 2011
Messages
42
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,595
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.

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?
 

Hello!

We connected SD with SPI interface, modified the code for this purpose.

The problem may be here: what did you change and why?
By the way, looking at your second code, are you bit-banging SPI? Or is it a test program?

Using the definitions you have in your second piece of code, try to write a
small program like this:

CS_H();
CS_L();
CS_H();

Do the same with MISO, MOSI and CLK

MISO_H();
MISO_L();
etc....

And verify with an oscilloscope that the right signal is at the right place.
Once it works, come back to your program.

By the way, there is something odd:

#define DIPORT P3OUT
#define DOPORT P3OUT

This is only for test, right?

Dora.
 
Hello Dora,

We have used Elm Chan's and wanted to change the code to work with SPI and MSP430F5438 as the code we have downloaded is for generic MCU. We could not find fat file system code for MSP430 series. There is also no code written for SPI interface.

The code is bit-banging SPI. As we are not experts in this programming, we are unsure about how to test this program.

We set up the fat file system, SPI and SD port declarations, than download the code into MSP430. After that we connected SD card to PC to see what's inside. The result was empty, no file is created.

Code:
#define DIPORT P3OUT
#define DOPORT P3OUT
This part is intended to be written to set up DI and DO ports of SD card to MSP430 (P3.4 and P3.5 pins)

Thanks for the answer, we will check the signal i/o at SPI pins.
 

Hello!

About the DIPORT / DOPORT stuff:
This part is intended to be written to set up DI and DO ports of SD card to MSP430 (P3.4 and P3.5 pins)

DI is data in (from the card point of view) and DO is data out.
Therefore DI should be linked to an output of the processor, and DO to some input.
In your definitions, both are linked to an output.

Beside this, it would be a good idea to use SPI, not bit banging. It works very well and there are
examples provided by TI.

Dora.
 
You are correct, we missed that point while working on other codes.
Besides, our codes for SPI write and receive is ;

Code:
void spi_send_byte(char spi_data)
{
    while(UCTXIFG == 0);
    UCA0TXBUF = spi_data;
}

char spi_get_byte(void)
{
	spi_send_byte(0xff);
	return spi_data;
}

This is not bit-banging right? (Setup for SPI is also ready and correct.)
 

Hello!

Yes, your code seems correct. But I don't know the codes by heart...
As long as you have the 4 lines CLK, MISO, MOSI and CS at the right place, it should work.

Dora.
 

Hello again Dora,

If you have worked with Elm Chan's code for FatFs, please let us know as we are stuck with f_mount function and depending on that, when we debug the project, we only see that there are problems with disk volume, mounting the disk and initialization.
Besides, we appreciate to know if there are any resources for this subject. Thank you for your answers.
 

Hello!

No, sorry, I wrote my own FAT FS. It is aimed at low power devices in which there
is usuall one SD card only. There is no need to mount the FAT in my case.

Dora.
 
Would you mind sending your own FatFs code if possible, to let us learn about some crucial and fundamental information about this Fat File System? If not, you are very welcome to ignore this message.
Thank you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top