MMC PROJECT PROBLEM

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
waves maker
Posts: 8
Joined: 09 Oct 2009 17:07

MMC PROJECT PROBLEM

#1 Post by waves maker » 09 Oct 2009 21:55

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);



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

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

#2 Post by Sobrietytest » 10 Oct 2009 04:49

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

waves maker
Posts: 8
Joined: 09 Oct 2009 17:07

#3 Post by waves maker » 10 Oct 2009 10:07

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.

nahian
Posts: 7
Joined: 24 Jun 2009 13:49

Re: MMC PROJECT PROBLEM

#4 Post by nahian » 08 Jul 2010 08:40

in 18f series, it is need to connect +ve in mclr pin.other wise,proteus (ISIS) shows error msg.
"MCU is reseting.."

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

Re: MMC PROJECT PROBLEM

#5 Post by anikolic » 08 Jul 2010 15:55

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
Web Department Manager

Post Reply

Return to “mikroC PRO for PIC General”