AnsweredAssumed Answered

SPI KE02

Question asked by Huy Nguyen on Dec 11, 2017
Latest reply on Dec 22, 2017 by Huy Nguyen

Hi

Here is my code for SPI, when I use oscilloscope to measure MISO, the data is true, but when I debug on CW, it always return 0

void SPI_Init(void)
{
SIM_SCGC |= SIM_SCGC_SPI0_MASK;
SPI0_C1 |= SPI_C1_MSTR_MASK; //master
SPI0_C1 &= ~SPI_C1_CPOL_MASK; //mode 2
SPI0_C1 |= SPI_C1_CPHA_MASK; //mode 2
/*SPI0_C1 |= SPI_C1_SSOE_MASK; //auto slave select
SPI0_C2 |= SPI_C2_MODFEN_MASK;//auto slave select*/
SPI0_C1 &= ~SPI_C1_SSOE_MASK; //manual slave select
SPI0_C2 &= ~SPI_C2_MODFEN_MASK; //manual slave select
SPI0_C1 &= ~SPI_C1_LSBFE_MASK;//msb
SPI0_C1 &= ~SPI_C1_SPIE_MASK; //no interrupt
SPI0_C1 &= ~SPI_C1_SPTIE_MASK;//no transfer interrupt
SPI0_C2 &= ~SPI_C2_SPC0_MASK;
SPI_SetBaudrate(1000000);
SPI0_C1 |= SPI_C1_SPE_MASK;
}

uint8_t SPI_SendAndRecvChar(uint8_t input)
{
while((SPI0_S & SPI_S_SPTEF_MASK) == 0);
SPI0_D = input;
while ((SPI0_S & SPI_S_SPRF_MASK) == 0);
/*uint8_t output;
output = SPI0_D;*/
return SPI0_D;
}

Outcomes