AnsweredAssumed Answered

Programming Issue

Question asked by Erik on Apr 30, 2013
Latest reply on May 1, 2013 by Clive One
Hi guys,
I've been working on interfacing an SD Card with this board but I'm having some issues on programming. The problem is that I've made a function to read a cluster on the sd card however as soon as I use that specific function the board just stop working by not executing anything that is in the main. The compiler doesn't give any errors so I don't know if it's a program issue or compiler
.
Here is the Main and the function that read the cluster.The IDE i'm using is CooCox CoIDE
//Here is the Main
int main(void){
    uint16_t Color = ACQUA;
    uint8_t Buffer[4096];
 
    Setup();
 
    LCD_DrawLine(10,8 ,400,398,Color);//These DrawLine doesn't works when I use the function SD_ReadCluster
    LCD_DrawLine(10,9 ,400,399,Color);
    LCD_DrawLine(10,10,400,400,Color);
    LCD_DrawLine(10,11,400,401,Color);
    LCD_DrawLine(10,12,400,402,Color);
 
    SD_ReadCluster(2,Buffer);//This is the function the makes the board not working
 
    while(1)
    {
        Delay(0xFFFFFF);
    }
}
 
void SD_ReadCluster(uint32_t cluster_number,uint8_t Cluster[]){
    uint32_t lba_addr = cluster_begin_lba + (cluster_number - 2) * sectors_per_cluster;
    uint16_t Var = 0xFF;
    uint8_t i;
    SD_CS_Clr;
    SD_Data(CMD18);
    SD_Data(lba_addr >> 24);
    SD_Data(lba_addr >> 16);
    SD_Data(lba_addr >> 8);
    SD_Data(lba_addr);
    SD_Data(0xFF);
    while (Var != R1_READY_STATE){
        Var = SD_Read();
    }
    for (i = 0;i < 8;i++){
        while (Var != DATA_START_BLOCK){
            Var = SD_Read();
        }
        for (Var = 0;Var < 512;Var++){
            Cluster[Var + 512 * i] = SD_Read(0xFF);
        }
        SD_Read();  //16 bit CRC
        SD_Read();  //16 bit CRC
    }
    SD_Data(CMD12);
    SD_Data(0x00);
    SD_Data(0x00);
    SD_Data(0x00);
    SD_Data(0x00);
    SD_Data(0xFF);
    while (Var != R1_READY_STATE){
        Var = SD_Read();
    }
    SD_CS_Set;
    SD_Data(0xFF);
}

These Are the Functions SD_Read() and SD_Data()
void SD_Data(uint8_t Data){
     SPI1->DR = Data;
     while( !(SPI1->SR & SPI_I2S_FLAG_RXNE) ); // wait until receive complete
}
uint8_t SD_Read(){
     SPI1->DR = 0xFF;
     while( !(SPI1->SR & SPI_I2S_FLAG_RXNE) ); // wait until receive complete
     return SPI1->DR;
}
Thanks in advance for any help.

Outcomes