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);
}
//***********************************************************
MMC PROJECT PROBLEM
-
- Posts: 619
- Joined: 05 Jul 2008 06:05
- Location: Thailand
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
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
-
- Posts: 8
- Joined: 09 Oct 2009 17:07
Re: MMC PROJECT PROBLEM
in 18f series, it is need to connect +ve in mclr pin.other wise,proteus (ISIS) shows error msg.
"MCU is reseting.."
"MCU is reseting.."
Re: MMC PROJECT PROBLEM
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
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