Mmc_Init() failed in proteus

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
magicboy_267
Posts: 2
Joined: 31 Aug 2013 05:09

Mmc_Init() failed in proteus

#1 Post by magicboy_267 » 31 Aug 2013 05:24

I"m working on a simple sd card project using mikroc's mmc library.
It will read CID register and display on Virtual terminal.
but mmc_init() doesn't work.
Anyone can help me?
I use pic18f452 with osc=20MHz.
MY schematic, hex file and mmc image file are included.
This is my code:

sbit Mmc_Chip_Select at LATC2_bit;
sbit Mmc_Chip_Select_Direction at TRISC2_bit;

char *text="SD CARD CID REGISTER";
void newline()
{
while (UART1_Tx_Idle()!=1){};
UART1_Write(0x0D);
while (UART1_Tx_Idle()!=1){};
UART1_Write(0x0A);
}
void main()
{
char message[16];
unsigned int error;
UART1_Init(9600);
delay_ms(100);
while (UART1_Tx_Idle()!=1){};
UART1_Write_Text(text);
newline();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
error= Mmc_Init();
if (error) UART1_Write_Text("failed");
else UART1_Write_Text("success");

SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Mmc_Read_Cid(message);
UART1_Write_Text(message);

}
Attachments
SDcard.rar
(39.82 KiB) Downloaded 487 times

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: Mmc_Init() failed in proteus

#2 Post by marina.petrovic » 02 Sep 2013 12:15

Hi,

Did you try your project on real hardware or only in Proteus?
We usually recommend to our users to try their projects on real hardware.

Please, make sure that your card is properly formatted.
MMC/SD card has to be formatted to FAT16 file system.

Please, can you try MMC example from our compiler to see whether you have the same problem with that example:
...\mikroC PRO for PIC\Examples\Extra Boards\MMC\MMC Fat16

I can't see the schematic or MMC image file from the folder that you posted.

Best regards,
Marina

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: Mmc_Init() failed in proteus

#3 Post by borris » 04 Sep 2013 12:18

Proteus works fine with MikroC and the FAT Libraries. The issues are filesystems that Proteus works with on the host. My solution was writing a small routine that allowed me to call FAT32_Format first. That gave me an image file that could be used on other projects.

jayanthd
Posts: 630
Joined: 08 May 2013 18:31
Location: Bangalore

Re: Mmc_Init() failed in proteus

#4 Post by jayanthd » 07 Oct 2013 13:05

What do you mean by not working. What should happen according to you code? I see there is a txt file inside the image file (.mmc file created using WinImage). The text inside the file is "This is File 1"

Do you want to write data received through UART to text file in the image file?

I have done SD card project using mikroC Compilers and it works fine in hardware and also Proteus. In Proteus you should not use the pullup resistors on the SPI lines with SD card.

To open .mmc file you have to rename it to .ima file and open it in WinImage.
Attachments
New folder.rar
(20.2 KiB) Downloaded 603 times
sdcard.png
sdcard.png (40.4 KiB) Viewed 5051 times
[HW:] EasyPIC v7, mikroProg PIC, AVR, STM32, PSoC, Tiva, 8051
[SW:] mikroC PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
mikroBasic PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
mikroPascal PRO PIC, dsPIC, PIC32, AVR, ARM, 8051
Visual GLCD, Visual TFT

Post Reply

Return to “User Projects”