Kwikstik SDcard witg SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kwikstik SDcard witg SPI

442 Views
mqxman
Contributor I

Hello, I would like to communicate kwikstik <--> SDcard over SPI. But it not going, the SDcard is in sockot on kwikstik.

char spi_send(char spiMsg) 

    char temp;

    while(!(SPI1_SR & SPI_SR_TFFF_MASK)); 

    {     

        asm("nop");  //While buffer is not empty do nothing 

    }

    SPI1_PUSHR = spiMsg & 0xff;    //Write char to SPI 

    while(!(SPI1_SR & SPI_SR_RFDF_MASK))

    {

        asm("nop");

    }

    temp = SPI1_POPR;

    SPI1_SR = SPI_SR_TFFF_MASK | (SPI1_SR & SPI_SR_RFDF_MASK);

    return temp;

}

void init_SPI1()        //SPI1 for SDcard

{

    SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;      //Turn on clock to module 

    SIM_SCGC6 |= SIM_SCGC6_SPI1_MASK;       //Enable SPI1 clock 

       

    PORTE_PCR6 = PORT_PCR_MUX(1);

    GPIOE_PDDR |= 1<<6;

    GPIOE_PSOR |= 1<<6;

    //Enable 3.3V to SDcard, see kwikstik schematics

//    PORTE_PCR4 = PORT_PCR_MUX(0x2);    //Set PTE4 to mux 2 [SPI1_PCS0]

    PORTE_PCR1 = PORT_PCR_MUX(0x2);    //Set PTE3 to mux 2 [SPI1_MOSI?] 

    PORTE_PCR2 = PORT_PCR_MUX(0x2);    //Set PTE1 to mux 2 [SPI1_SCK]

    PORTE_PCR3 = PORT_PCR_MUX(0x2);    //Set PTE2 to mux 2 [SPI1_MISO?]

   

    PORTE_PCR4 = PORT_PCR_MUX(1);    //PORTE1 is CS

    GPIOE_PDDR |= 1<<4;                //PORTE1 is output, for CS

   

    SPI1_MCR = 0;

    SPI1_MCR |= (SPI_MCR_MSTR_MASK | SPI_MCR_HALT_MASK | SPI_MCR_DCONF(0x0) | SPI_MCR_CLR_TXF_MASK | SPI_MCR_CLR_RXF_MASK);   //Set SPI1 to Master & SS pin to auto SS 

    SPI1_TCR =    SPI_TCR_SPI_TCNT(0x0);

    SPI1_CTAR0 = SPI_CTAR_FMSZ(7);

    SPI1_CTAR0 |= (SPI_CTAR_PBR(3) | SPI_CTAR_BR(10));

    SPI1_CTAR1 = SPI_CTAR_FMSZ(7);

    SPI1_CTAR1 |= (SPI_CTAR_PBR(3) | SPI_CTAR_BR(10));

    SPI1_MCR &= ~SPI_MCR_HALT_MASK;

}

What I doing wrong? Thank You!

Labels (1)
0 Kudos
1 Reply

354 Views
mjbcswitzerland
Specialist V

Hi

Which revision of the KWIKSTIK do you have?

Rev. 4 has errors which don't allow the SD card to be used without reworking - which is generaly not practical (neither SPI nor SHDC)

Rev. 5 is OK for SDHC mode.

Therefore it makes sense to use SDHC if you have a revision 5.

There is a reference here that will allow you to test the SD card operation:

http://www.utasker.com/kinetis/KWIKSTIK.html

Regards

Mark

0 Kudos