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
解決済! 解決策の投稿を見る。
Hi
What commands are you sending and which Flash type?
If you don't do a read command the Flash will not return data.
Also set a pull-up on the MISO line so that it doesn't float when the slave so not driving the line.
Regards
Mark
P.S. For professional requirements there are proven SPI Flash drivers for the KL17 for Atmel AT45DBxx, Spansion S25FL1-K, SST25, ST-MicroSTM25Pxxx and Windbond W25Q families, including simulation of the KL and the SPI Flash parts, in the uTasker project.
Thank you very much,
I was not sending the correct command so it explains why I wasn't getting data.
The small 50mV signal I was worried about was probably due to the lack of pull-up. Now that I have enable a (internal) pull-up and sent the correct command, everything works.
Does that SPI flash uTasker driver require to get a commercial (paid) licence ?
Hi
Most of the drivers are in the Open Source version but it is about 2 years behind the commercial version and so may not have all latest device support and features. If anything is missing or your prefer direct email and remote desk-top support you can request access to the commercial version. If you don't want to or can't pay for support you can request a free commercial license which is valid for one project/product and you can still get general free support at this forum.
Regards
Mark
I have tested a few changes in configuration regarding the SPI modes (the flash should allow for mode 0 or 3) and different baudrates (from 500kHz to 12MHz) and was not able to fix the issue.
I have also tried with a different external flash chip and got the same result. Here is the result of the transmission of 4 bytes using a succession or checking TxBuffer flag, sending with WriteBlocking, checking RxBufferFull and reading with ReadData, Channel one is MISO and channel two is SCLK.
EDIT : I am having the same signals whether the flash is connected or not.
Hi
What commands are you sending and which Flash type?
If you don't do a read command the Flash will not return data.
Also set a pull-up on the MISO line so that it doesn't float when the slave so not driving the line.
Regards
Mark
P.S. For professional requirements there are proven SPI Flash drivers for the KL17 for Atmel AT45DBxx, Spansion S25FL1-K, SST25, ST-MicroSTM25Pxxx and Windbond W25Q families, including simulation of the KL and the SPI Flash parts, in the uTasker project.
Hi Mark,
Thank you for answering,
Effectively I got the muxing wrong. MOSI is expected to be on PTC7 on our PCB schematics. I have therefore changed PTC6 and PTC7 to use Mux5 (and not 6 according to the datasheet).
The issue is therefore on the MISO pin and not MOSI pin. I will investigate and do more testing with other configuration as the issue might then come from the external flash chip the SPI peripheral is connected to.
Regards,
Nathan
Hi Nathan
Which pin are you measuring to try to see the MOSI output? Is it PTC6 or PTC7? Are you also sure that the pin is connected (measure directly on the chip to be sure).
Note that the SPI0_MOSI and SPI0_MISO can be swapped, based on the ALT2 or ALT6 MUX setting so make sure that you haven't swapped them around: ALT2 would give SPI0_MOSO on PTC6.
If you still don't make progress, read back the PORTC_PCR6 value to see whether it is as expected. If it isn't it may be being overwritten by something else trying to use the pin (eg. configuring it as an input).
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
KLx7: http://www.utasker.com/kinetis/FRDM-KL27Z.html / http://www.utasker.com/kinetis/Capuccino-KL27.html