Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is wrong with my code ??

Status
Not open for further replies.

afesheir

Member level 1
Joined
Feb 4, 2010
Messages
33
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,508
hi everybody ..
I hope I find my needs in this great board ..
Now I am trying to initialize MMC SanDisk 1GB using my own code (without using mikroC library) with PIC16F877A ..

When the card is initialized, I want my GLCD to display the word "Ready", otherwise I want to display "Initializing ..." ..

before anything, I want to display "WELCOME" ..

the GLCD is functioning properly alone, but with my code, the glcd displays nothing ..

here is my code:

Code:
//module connection

char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS  at RB2_bit;
sbit GLCD_RW  at RB3_bit;
sbit GLCD_EN  at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction  at TRISB2_bit;
sbit GLCD_RW_Direction  at TRISB3_bit;
sbit GLCD_EN_Direction  at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;


// Software SPI module connections
sbit SoftSpi_SDI at RC4_bit;
sbit SoftSpi_SDO at RC5_bit;
sbit SoftSpi_CLK at RC3_bit;

sbit SoftSpi_SDI_Direction at TRISC4_bit;
sbit SoftSpi_SDO_Direction at TRISC5_bit;
sbit SoftSpi_CLK_Direction at TRISC3_bit;
// End Software SPI module connections


void sendCommand(int cmdIndex);        //function prototype

void main() {
     unsigned char Response;


     Soft_SPI_Init(); // Init Soft_SPI
     Glcd_Init();     //Init. GLCD
//     Glcd_Set_Font(font5x7 , 5, 7, 32);// Change font
     Glcd_Fill(0x00); //Clear GLCD
     Glcd_Write_Text("WELCOME",0,0,1);


     TRISC.B1=0;    //Make RC2 output pin (CS or SS Pin)
     PORTC.B1=0;      //Hold CC=0
     delay_ms(4);     //Delay about 75 clock pulses at 20KHz

     sendCommand(0x00);   //CMD0 for S/W reset
Init:sendCommand(0x37);   //CMD55 to tell that the next command is Application Specific
     sendCommand(0x29);   //ACMD41 to Initialize the SD Card
     Response= Soft_Spi_Read([b][color=red]0x00[/color][/b]);

     if (Response==0x00)
     {
        Glcd_Fill(0x00);         //Clear GLCD
        Glcd_Write_Text("Ready !!",20,4,1);

     }
     else
     {
        Glcd_Fill(0x00);
        Glcd_Write_Text("Initializing ...",20,4,1);
        goto Init;
     }

}

void sendCommand(int cmdIndex)
{
     Soft_Spi_Write(0x40+cmdIndex);  //Send command of index cmdIndex
     Soft_Spi_Write(0x00);         //Send 4
     Soft_Spi_Write(0x00);         //Clear Bytes
     Soft_Spi_Write(0x00);         //As
     Soft_Spi_Write(0x00);         //Argument
     Soft_Spi_Write(0x95);         //CRC = 0x95 for CMD0 and not important for SPI mode
}

also I am asking about the red number, this function is to read data from spi bus, why do we need to assign data to send ..?

Great thanks to everybody ..
 

hay everybody .. I am in bad need to solve this bug !!
 

SPI transfers data in both directions on each clock pulse. There is no way of reading without a simultaneous write occurring. When only reading, any data can be placed on the outgoing wire but obviously you don't want it to be interpreted as a command so a 'do nothing' byte, 0x00 in your case, is used.

Brian.
 

thx betwixt .. I got it ..
also the GLCD now works fine .. it displays texts well ..
But is my code for MMC/SD initialization true .. I can't get the message "Ready" that indicates that the SD has been sucessfully initialized ..

As a troubleshooting technique, I want the GLCD to display the value of the response .. how can I do that ??

thx everybody >>>> up up >>
 

I'm guessing: If the response is not zero, you send initialization again without delay. Perhaps you should send initialization data then loop a few times to give the card chance to reply.

Brian.
 

thanks mate .. I tried ur solution and it worked fine .. great thanks ..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top