AnsweredAssumed Answered

SPI baremetal on the frdm-k64f

Question asked by dfgdgfg fdgfffgfg on Dec 13, 2015
Latest reply on Dec 17, 2015 by dfgdgfg fdgfffgfg

Hi

 

I'm trying to create my own SPI baremetal driver. But I was expecting a clock after the init because I set the continious clock register.

Why am I not seeing a clock on my oscilloscope?

[code]

int frdm_spi_init(SPI_Type *spi, struct frdm_spi_mode *mode, uint32_t hz) {

    if(mode->frame < FRDM_SPI_MIN_FRAME_SIZE) {

      return -1;

    }

    // Enable clock

    SIM_SCGC6 |= SIM_SCGC6_SPI0(FRDM_ENABLE);

    // For debug purpose

    SPI_MCR_REG(spi) &= ~SPI_MCR_CONT_SCKE_MASK;

    SPI_MCR_REG(spi) |= (FRDM_ENABLE<<SPI_MCR_CLR_RXF_SHIFT);

    // Master/slave

    SPI_MCR_REG(spi) &= ~SPI_MCR_MSTR_MASK;

    SPI_MCR_REG(spi) |= (mode->mode<<SPI_MCR_MSTR_SHIFT);

    if(mode->mode == FRDM_SPI_MASTER) {

      //Frame size

      SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_FMSZ_MASK;

      SPI_CTAR_REG(spi,0) |= (((mode->frame-1) & 0x0F)<<SPI_CTAR_FMSZ_SHIFT);

      // Spi mode

      SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_CPOL_MASK;

      SPI_CTAR_REG(spi,0) |= (mode->CPOL)<<SPI_CTAR_CPOL_SHIFT;

      SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_CPHA_MASK;

      SPI_CTAR_REG(spi,0) |= (mode->CPHA)<<SPI_CTAR_CPHA_SHIFT;

      //Always in msb mode

      SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_LSBFE_MASK;

 

    } else if(mode->mode == FRDM_SPI_SLAVE) {

      /*TODO*/

    }

    //frequency

    SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_ASC_MASK;

    SPI_CTAR_REG(spi,0) |= 1<<SPI_CTAR_ASC_SHIFT;

    SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_PASC_MASK;

    SPI_CTAR_REG(spi,0) |= 0<<SPI_CTAR_PASC_SHIFT;

 

    SPI_CTAR_REG(spi,0) &= ~SPI_CTAR_DBR_MASK;

    SPI_CTAR_REG(spi,0) |= 0<<SPI_CTAR_DBR_SHIFT;

   

    // Fifo

    SPI_MCR_REG(spi) &= ~SPI_MCR_DIS_TXF_MASK;

    SPI_MCR_REG(spi) != 0<<SPI_MCR_DIS_TXF_SHIFT;

 

    //Enable

    SPI_MCR_REG(spi) &= ~SPI_MCR_MDIS_MASK;

    SPI_MCR_REG(spi) != 0<<SPI_MCR_MDIS_SHIFT;

 

    // Start hardware

    SPI_MCR_REG(spi) &= ~SPI_MCR_HALT_MASK;

    SPI_MCR_REG(spi) |= 0<<SPI_MCR_HALT_SHIFT;

    return 0;

}

[/code]

Outcomes