This is what I'm configuring in setting up the K64 as master. Please let me know if you find something unexpected. Appreciate your help.
// Enable the clocks for Ports C and D and SPI0
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;
SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK;
// Configure the ports to be used by SPI0
PORTC_PCR4 = PORT_PCR_MUX(2); // CS
PORTC_PCR5 = PORT_PCR_MUX(2); // SCLK
PORTD_PCR2 = PORT_PCR_MUX(2); // MOSI
PORTC_PCR7 = PORT_PCR_MUX(2); // MISO
// Enable SPI0 IRQ
int irq = GET_IRQ_NUM(INT_SPI0);
set_irq_priority(irq, 7);
enable_irq(irq);
// Configure SPI0 registers
SPI0_BR = X; // I tried multiple baud rate values but the output has the same form but different duration
// Disable and clear SPI
SPI0_MCR &= (~ SPI_MCR_MDIS_MASK);
SPI0_MCR = SPI_MCR_HALT_MASK | SPI_MCR_CLR_TXF_MASK | SPI_MCR_CLR_RXF_MASK;
SPI0_MCR |= SPI_MCR_MSTR_MASK;
SPI0_CTAR = SPI_CTAR_CPOL_MASK | SPI_CTAR_FMSZ(7) | ;
// Receive FIFO Overflow Overwrite Enable
SPI0_MCR |= SPI_MCR_ROOE_MASK;
// Set CS0-7 inactive high
SPI0_MCR |= SPI_MCR_PCSIS_MASK;
// Receive FIFO Overflow Request Enable
SPI0_RSER |= SPI_RSER_RFOF_RE_MASK;
// Clear all flags
SPI0_SR = 0xFFFFFFFF;
// Enable SPI
SPI0_MCR &= ~SPI_MCR_HALT_MASK;