Hi
I used the following code for initializing my SPI0 in FRDM K82 board,
But I do not see clock and MOSI data through scope and data except chip select, Can you please help me.
void spiinit()
{
//Clock settings
SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK; //
SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK;
//Port Settings
PORTD->PCR[0] |= PORT_PCR_MUX(2); // CS
PORTD->PCR[1] |= PORT_PCR_MUX(2); // SCK
PORTD->PCR[2] |= PORT_PCR_MUX(2); // SOUT
PORTD->PCR[3] |= PORT_PCR_MUX(2); // SIN
SPI0->MCR =0;
SPI0->CTAR[0] = 0;
//-------------------------------------
SPI0->MCR |= SPI_MCR_MSTR_MASK;
SPI0->MCR |= SPI_MCR_DCONF(0)|(0 << SPI_MCR_FRZ_SHIFT);
SPI0->MCR |= SPI_MCR_PCSIS(1) | SPI_MCR_MDIS(0); // Module enable
SPI0->MCR |= (1 << SPI_MCR_DIS_TXF_SHIFT)| (1 << SPI_MCR_DIS_RXF_SHIFT);
SPI0->MCR |= (1 << SPI_MCR_HALT_SHIFT); // stop transfer
PRINTF("SPI0->MCR=%x\n",SPI0->MCR);
SPI0->CTAR[0] |= (0 << SPI_CTAR_DBR_SHIFT);
SPI0->CTAR[0] |= SPI_CTAR_FMSZ(15); // frame size 16
SPI0->CTAR[0] |= (0 << SPI_CTAR_CPOL_SHIFT);// CPOL=0;
SPI0->CTAR[0] |= (0 << SPI_CTAR_CPHA_SHIFT);// CPHA=0;
SPI0->CTAR[0] |= (0 << SPI_CTAR_LSBFE_SHIFT);//MSB first
SPI0->CTAR[0] |= SPI_CTAR_PCSSCK(0) ;
SPI0->CTAR[0] |= SPI_CTAR_CSSCK(1) ;
SPI0->CTAR[0] |= SPI_CTAR_ASC(0) ;
SPI0->CTAR[0] |= SPI_CTAR_PDT(3) ;
SPI0->CTAR[0] |= SPI_CTAR_DT(5) ;
SPI0->CTAR[0] |= SPI_CTAR_BR(1);
PRINTF("SPI0->CTAR[0]=%x\n",SPI0->CTAR[0]);
SPI0->SR = SPI_SR_TFFF(1); // cleared by writing 1 after module enable
SPI0->RSER = SPI_RSER_TCF_RE(1)|SPI_RSER_EOQF_RE(1);
}
int main(void)
{
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
spiinit();
SpiWrite = 0x8180;
SPI0->MCR &= ~(SPI_MCR_HALT_MASK | SPI_MCR_FRZ_MASK);
SPI0->SR &= ~SPI_SR_EOQF_MASK;
SPI0->PUSHR = (SPI_PUSHR_EOQ_MASK | SPI_PUSHR_PCS(1) | SpiWrite);
while(!(SPI0->SR & SPI_SR_TCF_MASK));
SPI0->SR |= SPI_SR_TCF_MASK | SPI_SR_EOQF_MASK;
SPI0->MCR |= SPI_MCR_HALT_MASK;
for(;;) { /* Infinite loop to avoid leaving the main function */
__asm("NOP"); /* something to use as a breakpoint stop while looping */
}
}
Please help if there is any mistake.
Thanks
Gokul.
Hi Gokulnath Kasinathan,
Seems that you have download the MCUXpresso SDK. Why not direct refer the dpsi examples in it's folder?
For example: You can modify the SPI0 pins in BOARD_InitPins function of dspi_polling_b2b_transfer_master example. Check if these pins are able to output waveform.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Please add this part inside for loop :
SPI0->MCR &= ~(SPI_MCR_HALT_MASK | SPI_MCR_FRZ_MASK);
SPI0->SR &= ~SPI_SR_EOQF_MASK;
SPI0->PUSHR = (SPI_PUSHR_EOQ_MASK | SPI_PUSHR_PCS(1) | SpiWrite);
while(!(SPI0->SR & SPI_SR_TCF_MASK));
SPI0->SR |= SPI_SR_TCF_MASK | SPI_SR_EOQF_MASK;
SPI0->MCR |= SPI_MCR_HALT_MASK;
And SPI_MCR_MDIS(0); ı am not sure but as ı remember after init make module active
I hope it will work..