+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Newbie level 4
    Points: 602, Level: 5

    Join Date
    Jul 2011
    Posts
    5
    Helped
    0 / 0
    Points
    602
    Level
    5

    interfacing a dspic with an sd card

    Hello, I have been trying to write a text file in an sd card with a pic33fj128gp802, im using the MikroC for dspic MMC library but it wont work
    I'll paste the code in here for you to see, the code is ok until the part I try to write, i've tested the code by creating the txt but not writing to it and
    it is OK, but as soon as I add the writing part, the pic does nothing at all, please tell me if you know whats going on.


    void main() {
    char Contenido[9];
    Contenido[9] = "HOLA JUAN";
    AD1PCFGL = 0XFFFF; //TODOS LOS PINES COMO DIGITALES
    DCICON1 = 0X0701;
    DCICON2 = 0X0C6F;
    DCICON3 = 0X0000;
    TRISA = 0X0000; // TODOS LOS PINES COMO SALIDA
    TRISB = 0x00E2; //ASIGNA EL PIN RB7, RB6, RB5 Y RB1 COMO ENTRADA Y LOS DEMAS SALIDA
    RSCON = 0X0005;
    TSCON = 0X0000;
    UNLOCK_IOLOCK();
    RPOR0 = 0X000D; //ASIGNA CSOUT A RP0
    RPINR20 = 0X0001; //ASIGNA SPI INPUT A RP1
    RPOR1 = 0X0807; //ASIGNA SPI OUTPUT A RP2 Y SPI CLOCK OUTPUT A RP3
    RPINR24 = 0X0507; //ASIGNA CSCK Y CSDI A RP5 Y RP7
    RPINR25 = 0X0006; //ASIGNA COFS A RP6
    LATA = 0X0;
    LATB = 0X0;
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_16,_SPI_SS_DISABLE,
    _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
    if (!Mmc_Fat_Init()) {
    LATB.B8 = 1;
    Mmc_Fat_Assign("JUAN.TXT", 0XA0);
    Mmc_Fat_Rewrite();
    Mmc_Fat_Write("HOLA JUAN", 10);
    }
    else {
    LATB.B8 = 1;
    delay_ms(1000);
    LATB.B8 = 0;
    }
    }

    •   AltAdvertisment

        
       

  2. #2
    Member level 1
    Points: 1,187, Level: 7

    Join Date
    Oct 2010
    Location
    ahmedabad/gujarat
    Posts
    34
    Helped
    2 / 2
    Points
    1,187
    Level
    7

    Re: interfacing a dspic with an sd card

    Quote Originally Posted by rikrdos6 View Post
    Hello, I have been trying to write a text file in an sd card with a pic33fj128gp802, im using the MikroC for dspic MMC library but it wont work
    I'll paste the code in here for you to see, the code is ok until the part I try to write, i've tested the code by creating the txt but not writing to it and
    it is OK, but as soon as I add the writing part, the pic does nothing at all, please tell me if you know whats going on.


    void main() {
    char Contenido[9];
    Contenido[9] = "HOLA JUAN";
    AD1PCFGL = 0XFFFF; //TODOS LOS PINES COMO DIGITALES
    DCICON1 = 0X0701;
    DCICON2 = 0X0C6F;
    DCICON3 = 0X0000;
    TRISA = 0X0000; // TODOS LOS PINES COMO SALIDA
    TRISB = 0x00E2; //ASIGNA EL PIN RB7, RB6, RB5 Y RB1 COMO ENTRADA Y LOS DEMAS SALIDA
    RSCON = 0X0005;
    TSCON = 0X0000;
    UNLOCK_IOLOCK();
    RPOR0 = 0X000D; //ASIGNA CSOUT A RP0
    RPINR20 = 0X0001; //ASIGNA SPI INPUT A RP1
    RPOR1 = 0X0807; //ASIGNA SPI OUTPUT A RP2 Y SPI CLOCK OUTPUT A RP3
    RPINR24 = 0X0507; //ASIGNA CSCK Y CSDI A RP5 Y RP7
    RPINR25 = 0X0006; //ASIGNA COFS A RP6
    LATA = 0X0;
    LATB = 0X0;
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_16,_SPI_SS_DISABLE,
    _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
    if (!Mmc_Fat_Init()) {
    LATB.B8 = 1;
    Mmc_Fat_Assign("JUAN.TXT", 0XA0);
    Mmc_Fat_Rewrite();
    Mmc_Fat_Write("HOLA JUAN", 10);
    }
    else {
    LATB.B8 = 1;
    delay_ms(1000);
    LATB.B8 = 0;
    }
    }

    first you read the complete spi manual and set the register value as per your requirement and you first test on simulator then try to implement on hardware..........



--[[ ]]--