Try this, it may help
extern sfr sbit Mmc_Chip_Select at RC0_bit;
extern sfr sbit Mmc_Chip_Select_Direction at TRISC0_bit;
0 1 mikroCPIC1618.exe -MSF -DBG -pP18F4520 -DL -O11111114 -fo10 -N"C:\Users\User\Desktop\MikroC testing\MMC.mcppi" -SP"C:\Program Files (x86)\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files (x86)\Mikroelektronika\mikroC PRO for PIC\uses\P18\" -SP"C:\Users\User\Desktop\MikroC testing\" "MMC.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_Button.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl"
0 125 All files Preprocessed in 32 ms
0 121 Compilation Started MMC.c
22 122 Compiled Successfully MMC.c
0 126 All files Compiled in 78 ms
0 359 Unresolved extern 'islower' __Lib_MmcFat16.c
0 359 Unresolved extern 'islower' __Lib_MmcFat16.c
0 359 Unresolved extern 'toupper' __Lib_MmcFat16.c
0 359 Unresolved extern 'toupper' __Lib_MmcFat16.c
0 359 Unresolved extern 'islower' __Lib_MmcFat16.c
0 0
0 102 Finished (with errors): 03 Sep 2011, 15:46:44 MMC.mcppi
Hi guys,
I have remodified the code from user manual MMC's example by interfacing to my 16x2 LCD instead UART.
Code:sbit Mmc_Chip_Select at LATC0_bit; // for writing to output pin always use latch (PIC18 family) sbit Mmc_Chip_Select_Direction at TRISC0_bit; // eof MMC module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D7 at RB3_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D4 at RB0_bit; // Pin direction sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D7_Direction at TRISB3_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB0_bit; // Variables for MMC routines unsigned char SectorData[512]; // Buffer for MMC sector reading/writing unsigned char data_for_registers[16]; // buffer for CID and CSD registers // UART1 write text and new line (carriage return + line feed) /* void UART1_Write_Line(char *uart_text) { UART1_Write_Text(uart_text); UART1_Write(13); UART1_Write(10); } */ // Display byte in hex void PrintHex(unsigned char i) { unsigned char hi,lo; hi = i & 0xF0; // High nibble hi = hi >> 4; hi = hi + '0'; if (hi>'9') hi=hi+7; lo = (i & 0x0F) + '0'; // Low nibble if (lo>'9') lo=lo+7; // UART1_Write(hi); // UART1_Write(lo); } void main() { const char FILL_CHAR = 'm'; unsigned int i, SectorNo; char mmc_error; bit data_ok; ADCON1 |= 0x0F; // Configure AN pins as digital CMCON |= 7; // Turn off comparators TRISB = 0; PORTB = 0xFF; Delay_ms(2500); // UART1_Write_Line("PIC-Started"); // PIC present report // Initialize SPI1 module SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); Lcd_Init(); // Initialize GLCD Lcd_Out(1,1,"PIC-STARTED"); Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR); // initialise a MMC card mmc_error = Mmc_Init(); if(mmc_error == 0) Lcd_Out(2,1,"MMC INIT OK"); else Lcd_Out(2,1,"MMC INIT ERROR"); // Fill MMC buffer with same characters for(i=0; i<=511; i++) SectorData[i] = FILL_CHAR; // Choose sector SectorNo = 590; // Write sector mmc_error = Mmc_Write_Sector(SectorNo, SectorData); if(mmc_error == 0) // UART1_Write_Line("Write-OK"); Lcd_Out(1,1,"WRITE OK"); else // if there are errors..... //UART1_Write_Line("Write-Error"); Lcd_Out(1,1,"Write ERROR"); Delay_ms(5000); // Reading of CID register mmc_error = Mmc_Read_Cid(data_for_registers); if(mmc_error == 0) { // UART1_Write_Text("CID : "); Lcd_Out(2,1,"CID"); for(i=0; i<=15; i++) PrintHex(data_for_registers[i]); // UART1_Write_Line(""); } else // UART1_Write_Line("CID-error"); Lcd_Out(2,1,"CID-ERROR"); // Reading of CSD register mmc_error = Mmc_Read_Csd(data_for_registers); if(mmc_error == 0) { // UART1_Write_Text("CSD : "); Lcd_Out(1,1,"CSD: "); for(i=0; i<=15; i++) PrintHex(data_for_registers[i]); // UART1_Write_Line(""); } else // UART1_Write_Line("CSD-error"); Lcd_Out(1,1,"CSD-error"); // Read sector mmc_error = Mmc_Read_Sector(SectorNo, SectorData); if(mmc_error == 0) { //UART1_Write_Line("Read-OK"); Lcd_Out(1,1,"Read-ok"); // Chech data match data_ok = 1; for(i=0; i<=511; i++) { //UART1_Write(SectorData[i]); if (SectorData[i] != FILL_CHAR) { data_ok = 0; break; } } //UART1_Write_Line(""); if (data_ok) // UART1_Write_Line("Content-OK"); Lcd_Out(1,1,"Content Ok"); else //UART1_Write_Line("Content-Error"); Lcd_Out(1,1," Content ERROR"); } else // if there are errors..... //UART1_Write_Line("Read-Error"); Lcd_Out(1,1,"Read Error"); // Lcd_Cmd(_LCD_CLEAR); // Signal test end //UART1_Write_Line("Test End."); Delay_ms(5000); Lcd_Out(1,1,"Test End"); }
View attachment 61013
These'r my brief schematics diagram.
I have use multi-meter to measure the input of my SD card circuit which around 3.5-3.6V.
I have compiled & tested . The LCD just display MMC init Error & Write Error and didnt show until "Test End".
I have formatted my SD card 1GB with my windows 7(ulti) 64bits with following settings:
Fat (default), Allocation Size : Default
My mikroC PIC18f4520 oscillator value have tried 8 & 10 Mhz.
Any idea how to fix this ?
Sorry for lengthy above description.
check your SD card connections.. the mikroc is working
this should be the result in your LCD
check the image
check your SD card connections.. the mikroc is working
this should be the result in your LCD
check the image
search proteus and you can download the trial version.proteus is a very good simulator
RC6 and RC7 is a uart PIN dont mind it because you dont have uart..
I suggest you to focus on sd card initialization and remove all codes for a while.. as soon as you got it working or the sd card detected then that's the time you add code for another function..
---------- Post added at 17:16 ---------- Previous post was at 17:13 ----------
monitor every value returned by every function in sd card routine..
read the manual of mikcroC what is the return of every function ..]
example if the initialization successful then it will return a 1 value then if it returns 1 then display in "lcd initialization complete" in your LCD..
debug it step by step
of course yes.. check the image mikroC IDE is still openYour attachment result diagram, is it mikroC example code.
debug does not only mean by using proteus.."Debug", are you referring the proteus simulation ?
what version of mikroC you are using.? but I dont believe the error is logical...I tried to build exactly the same example code provided in MikroC library files but unfortunately i am receiving logical and syntax errors.
sfr sbit Mmc_Chip_Select at RC2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC2_bit;
// MMC module connections
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
void main(){
char mmc_error;
ADCON1 = 0x0F;
CMCON = 0x07;
TRISB = 0;
PORTB = 0xFF;
// Initialize SPI1 module and set pointer(s) to SPI1 functions
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Lcd_init();
Lcd_out(2,1,"Test start");
Delay_ms(2000);
mmc_error = Mmc_Init();
if(mmc_error == 0)
Lcd_out(1,1,"MMC Init-OK"); // If MMC present report
else
Lcd_out(1,1,"MMC Init-error"); // If error report
Mmc_Fat_Assign("MIKROELE.TXT",0xA0);
}
did you set the configuration bits of your device properly?
---------- Post added at 08:16 ---------- Previous post was at 08:15 ----------
post here your configuration bits setting..
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?