AnsweredAssumed Answered

KL17 SPI data not send on MOSI but CLK and MISO working

Question asked by nathan55421 on Oct 17, 2017
Latest reply on Oct 18, 2017 by Mark Butcher

Hi everyone,

 

I am using a MKL17 MCU with the Kinetis driver (with current SPI driver version 2.0.3).

I want to communicate through SPI with an external flash module on a custom board.

The configuration of the pins and SPI peripheral is :

 

/* Enable the module clock */
CLOCK_EnableClock(kCLOCK_PortC);

/* Set alternative function for SPI pins (CS, SCK, MOSI, MISO) */
PORT_SetPinMux(PORTC, 4, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTC, 5, kPORT_MuxAlt2);
PORT_SetPinMux(PORTC, 6, kPORT_MuxAlt2);
PORT_SetPinMux(PORTC, 7, kPORT_MuxAlt2);

SPI_MasterGetDefaultConfig (&m_spiMasterConfig);
/* Set baudrate */
m_spiMasterConfig.baudRate_Bps = m_ptrSpiConfig->baudrate;
/* Set SS pin */
m_spiMasterConfig.outputMode = kSPI_SlaveSelectAsGpio;
/* Get source clock frequency */
wSourceClockFrequency = CLOCK_GetFreq(kCLOCK_BusClk);
/* Initialize SPI master */
SPI_MasterInit(SPI0, &m_spiMasterConfig, wSourceClockFrequency);
/* Disable FIFO */
SPI_EnableFIFO(SPI0, false);
/* Enable interrupt */
SPI_Enable(SPI0, true);

 

I set the CS pin as GPIO and try sending data as follow :

 

GPIO_WritePinOutput(GPIOC, 4, 0);
while(!(SPI_GetStatusFlags(SPI0) & kSPI_TxBufferEmptyFlag));
SPI_WriteBlocking(SPI0, 0x06);
while(!(SPI_GetStatusFlags(SPI0) & kSPI_RxBufferFullFlag));
wDataIn = SPI_ReadData(SPI0)
GPIO_WritePinOutput(GPIOC, 4, 1);

I have plugged an oscilloscope on the pins and I can see the CLK signal going out of the PTC4 pin as well as the CS pin being set and the MISO line being triggered by my flash module.

Unfortunately when I look at the MOSI line, I only see some noise (signal smaller than 100mV) instead of the 3V of the operating MCU.

 

Here is what I have on the oscilloscope, when sending 5 bytes of data.

Channel 2 is connected to SCLK and channel 1 to MOSI (notice the difference in scale)

 

Does anyone have an idea ?

 

Regards,

Nathan

Outcomes