AnsweredAssumed Answered

Stuck with LPSPI (MKE14F)

Question asked by Michael Heidinger on May 15, 2017
Latest reply on Jul 10, 2017 by Michael Heidinger

Dear Forum,

i just want to send out plain data over SPI, it can't be too hard, right?

However, I'm stuck with it, maybe you guys can help me out.

 

Code:

void lpspi_init(void){
    //configure port
    PCC->CLKCFG[PCC_PORTD_INDEX]=PCC_CLKCFG_CGC(1);
    PORTD->PCR[0]=PORT_PCR_MUX(3);
    PORTD->PCR[1]=PORT_PCR_MUX(3);
    PORTD->PCR[2]=PORT_PCR_MUX(3);
    PORTD->PCR[3]=PORT_PCR_MUX(3);

 

 

    //Set FIRCDIV2
    SCG->FIRCDIV=SCG_FIRCDIV_FIRCDIV2(1)|SCG_FIRCDIV_FIRCDIV1(1);
    //configure
    PCC->CLKCFG[PCC_LPSPI1_INDEX]=PCC_CLKCFG_CGC(1)|PCC_CLKCFG_PCS(3); //Set fast irc clock

 

    //Reset module
    // Reset all internal logic and registers, except the Control Register. Remains set until cleared by software.
    LPSPI1->CR |= LPSPI_CR_RST_MASK;
    // Software reset doesn't reset the CR, so manual reset the FIFOs
    LPSPI1->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
    // Master logic is not reset and module is disabled.
    LPSPI1->CR = 0x00U;

 

 

 

    //Set SPI to master mdoe
    LPSPI1->CFGR0=LPSPI_CFGR0_HRSEL(1);  //does not work with 0 too.
    LPSPI1->CFGR1=LPSPI_CFGR1_MASTER(1);
    LPSPI1->TCR=LPSPI_TCR_PRESCALE(1)|LPSPI_TCR_PCS(1)|LPSPI_TCR_FRAMESZ(8);
    LPSPI1->CCR= 0x04090808;
    LPSPI1->FCR=0x00000003;
    LPSPI1->CR=LPSPI_CR_MEN(1);

 

}

 

I'm not getting any output on the pins. Where's my problem?

I then write test data to it:

LPSPI1->TDR=0b01010101;

 

However I do not see anythings on the pins.

1. Is my clock right? Fast IRC is running on 48MHz.

Can somebody please assit me to get the code running?

 

-Michael

Outcomes