4 years, 11 months ago.

spi0 port not activated on mbed

The k22f has a SPI0 port on PC5, PC6, PC7 that does not seem to be usable in mbed. Every time I try to instantiate a spi object on these pins the rgb led blinks and the board is not active. Do any one have any idea on how I could get this port to work ?

I am currently bit - banging a spi port on this pins and I cannot achieve a transfer rate higher than 500kHz

Regards

Question relating to:

The FRDM-K22F is an ultra-low-cost development platform for Kinetis K Series K2x (K22F) MCUs built on ARM® Cortex™-M4 processor. Features include easy access to MCU I/O, battery-ready, low-power operation, a …

Hi Jonathan, Can you please show me your code for setting the k22f as I am facing the same problems for days without any solution

posted by Richard Mensah 10 Mar 2016

2 Answers

4 years, 11 months ago.

This is the list of SPI pins defined in the source files. At least make sure you have the latest version of the mbed library:

/************SPI***************/
const PinMap PinMap_SPI_SCLK[] = {
    {PTD1 , SPI_0, 2},
    {PTE2 , SPI_1, 2},
    {PTA15, SPI_0, 2},
    {PTB11, SPI_1, 2},
    {PTC5 , SPI_0, 2},
    {PTD5 , SPI_1, 7},
    {NC   , NC   , 0}
};
 
const PinMap PinMap_SPI_MOSI[] = {
    {PTD2 , SPI_0, 2},
    {PTE1 , SPI_1, 2},
    {PTE3 , SPI_1, 7},
    {PTA16, SPI_0, 2},
    {PTB16, SPI_1, 2},
    {PTC6 , SPI_0, 2},
    {PTD6 , SPI_1, 7},
    {NC   , NC   , 0}
};
 
const PinMap PinMap_SPI_MISO[] = {
    {PTD3 , SPI_0, 2},
    {PTE1 , SPI_1, 7},
    {PTE3 , SPI_1, 2},
    {PTA17, SPI_0, 2},
    {PTB17, SPI_1, 2},
    {PTC7 , SPI_0, 2},
    {PTD7 , SPI_1, 7},
    {NC   , NC   , 0}
};

Accepted Answer

Thanks for this answer ! I should have the latest mbed library (using the online compiler) but i' don't get why when instantiating this SPI port, the freedom board gets all blinky (definitely not in my code).

posted by Jonathan Piat 10 Apr 2015

I will have a look at it later. Only can you describe what you mean by all blinky? It should just blink the red LED, and due to state of the RGB LED it might result in other colors, but in the end it should just be a two-color blink.

Btw related to software SPI: DigitalOut on KSDK targets are horribly slow (blame Freescale for their library), you can use this lib if you really want fast IO: http://developer.mbed.org/users/Sissors/code/FastIO/. On most targets this gives a nice speed improvement, on KSDK targets a gigantic speed improvement.

posted by Erik - 10 Apr 2015

Works fine for me. Are you sure you have them in the correct order?

posted by Erik - 11 Apr 2015

IIn fact the problem is that i was misleaded by Freescale data sheet ... On freescale datasheet PTC7 is SPI0_SIN which i assumed was SlaveIN (like in MOSI) but is apparently SerialIn and thus refers to MISO ... Vendor should take great care to use good naming conventions to avoid this issue.

posted by Jonathan Piat 11 Apr 2015
4 years, 11 months ago.

Hi,
Seeing the platform information, I think we should use

PTD6 for MOSI
PTD7 for MISO
PTD5 for SCK

moto

after seeing Erik-san's comment...
I'm sorry, for SPI0, PTC5, PTC6, PTC7 should be valid
moto

posted by Motoo Tanaka 10 Apr 2015