Page 1 of 1

MMC PROJECT PROBLEM

Posted: 09 Oct 2009 21:55
by waves maker
I HOPE IF I CAN FIND ANY HELP HERE

I MAKE A MMC PROJECT AND MAKE THE SIMULATION AT THE PROTEUS

I COULD WRITE/READ SECTORS FROM THE MMC AND READ THE CID AND CSD REGISTER AND THAT WORK SO VERY GOOD.

BUT WHEN I WRITE THE COMMAND
Mmc_Fat_Init(); DO NOT WORK

AND WHEN I WRITE THE COMMAND
Mmc_Fat_Assign("MIKROELE.TXT",0xA0); I GET WARNING MESSAGE

"STACK OVERFLOW IS FORCING DEVICE RESET"

AND THE MICRO RESET UNLIMITED TIMES

MICROCONTROLLER:PIC18F4520
MIKROC 2009 V250

THE PROGRAM

//***********************************************************
sbit Mmc_Chip_Select at RC2_bit;
sbit Mmc_Chip_Select_Direction at TRISC2_bit;
void main()
{
char error;
trisb=0;portb=0;
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);

Mmc_Init();
Mmc_Fat_Init();
Mmc_Fat_Assign("MIKROELE.TXT",0xA0);



}
//***********************************************************

Posted: 10 Oct 2009 04:49
by Sobrietytest
When you work with FAT you don't need to use the Mmc_Init() command, what is happening with your program is that you initialise the SPI but the Mmc_Init() reinitialises it, after that the Mmc_Fat functions will not work properly.

After you use the Mmc_Fat_Init() command you can then speed up the SPI otherwise the card functions will be very slow...

//***********************************************************
sbit Mmc_Chip_Select at RC2_bit;
sbit Mmc_Chip_Select_Direction at TRISC2_bit;
void main()
{
char error;
trisb=0;portb=0;
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);

Mmc_Fat_Init();

// reinitialise SPI1 at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);

Mmc_Fat_Assign("MIKROELE.TXT",0xA0);

}
//***********************************************************


You should also provide some error checking in case there is a problem with the card, Mmc_Fat_Init() returns 0, 1 or 255 (see help files) depending on the card condition, so you can change your code like this...


SPI1_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);

if (!Mmc_Fat_Init()) { //if the initialise was successful
// reinitialise SPI1 at higher speed
SPI1_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
}
else{ //if the initialise was unsuccessful...
// put your error handling code here
}


ST

Posted: 10 Oct 2009 10:07
by waves maker
i really thank you mr.Sobrietytest for your repply and your time.
put for sorrow the problem still exist and the stack still over flow and reset the micro, i hope if you have another solution i can do , and thanks again.

Re: MMC PROJECT PROBLEM

Posted: 08 Jul 2010 08:40
by nahian
in 18f series, it is need to connect +ve in mclr pin.other wise,proteus (ISIS) shows error msg.
"MCU is reseting.."

Re: MMC PROJECT PROBLEM

Posted: 08 Jul 2010 15:55
by anikolic
Hello,

First of all, I warmly recommend you to switch over to mikroC PRO for PIC v3.80, in order to be absolutely sure that this is not something compiler-related.
Secondly, in order to help you, I would really need your entire project folder zipped, so I could recreate this error condition and provide you with explanation or workaround.
Although your program should always keep track of stack level utilization, you should know that Stack Overflow Reset can be turned off in Project->Edit Project Windows, where configuration bits are set.

If you want a private investigation, please open a support ticket at http://www.mikroe.com/esupport

Best regards,
Aleksandar