AnsweredAssumed Answered

Kwikstik SDcard witg SPI

Question asked by Norbert Gal on Jan 27, 2016
Latest reply on Jan 27, 2016 by Mark Butcher

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!

Outcomes