9 years, 8 months ago.

FRDM-K64F, SD-CARD and RF/WIFI extensions interfering each other?

Hi all,

I am working to a project based on the FRDM-K64F in which I need to use at the same time the SD-CARD interface to log some data on an SD-CARD and the RF/WIFI extension interface to send/receive messages on the air using a nRF24L01P.

I tested separately two demo programs for the SDFileSystem (http://mbed.org/users/simon/code/SDFileSystem_HelloWorld/) and the nRF24L01P (http://mbed.org/cookbook/nRF24L01-wireless-transceiver) and they work perfectly; however, when I merge them together to have both features in the same program, the RF module stops responding and reports an error on the TX data size

It seems like that when I initialize the SDFileSystem in the same program with the RF module, the SPI interface to the latter is disabled or something similar, nonetheless the signals used by the two interfaces belong to different ports of the microcontroller.

For the sake of completeness, the following code

.....

#define LOG_ON_SDCARD
....
 // nRF24L01+ Interface
 #define NRF_MOSI  PTD6
 #define NRF_MISO  PTD7
 #define NRF_SCK   PTD5
 #define NRF_CSN   PTD4 
 #define NRF_CE    PTC12
 #define NRF_IRQ   PTC18

 // SD-CARD Interface
 #define SD_MOSI		PTE3
 #define SD_MISO		PTE1
 #define SD_SCLK		PTE2
 #define SD_CS	        PTE4
....

nRF24L01P my_nrf24l01p(NRF_MOSI, NRF_MISO, NRF_SCK, NRF_CSN, NRF_CE, NRF_IRQ);    // mosi, miso, sck, csn, ce, irq

#ifdef LOG_ON_SDCARD
	SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, "sdcard");
	FILE *fp = NULL;
#endif
...

causes this report from the nRF24l01+ module:

nRF24L01+ Frequency : 2527 MHz nRF24L01+ Output power : 0 dBm nRF24L01+ TX Address : 0xFFFFFFFFFF nRF24L01+ RX Address : 0xFFFFFFFFFF nRF24L01P: Unknown Air Data Rate value 40 ==> error!

If I undefine the symbol LOG_ON_SDCARD, the RF module responds correctly:

nRF24L01+ Frequency : 2402 MHz nRF24L01+ Output power : 0 dBm nRF24L01+ TX Address : 0xDEADBEEF0F nRF24L01+ RX Address : 0xE7E7E7E7E7 nRF24L01+ Data Rate : 1000 kbps

Is there anyone else that has experimented this strange behaviour on the FRDM-K64F?

Of course I will continue to investigate independently on this problem but any hint will be appreciated.

Sorry to reopen an old thread, but does anyone know where the PinMap function integers are noted?

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},
    {PTB23, SPI_2, 2},
    {PTC7 , SPI_0, 2},
    {PTD7 , SPI_1, 7},
    {NC   , NC   , 0}
};

I'm seeing 2 and 7 used alot, and need to understand what they mean. I'm using 2 separate SPI peripherals, but still have a conflict of simultaneous usage. I have a feeling the answer is in these function ints...

Thanks

posted by Angus Hutton-McKenzie 01 Feb 2017

1 Answer

9 years, 8 months ago.

Use <<code>> and <</code>> to make code readable.

What is the issue however are your SPI ports. While they are different pins, they share one and the same SPI hardware unit. The libraries don't take this into account, and they will generally interfere (they will for sure when like in your situation both need the MISO line, I have had it with an LCD display where only one required that line, and there it could be made to work properly).

Here are the pinouts: http://mbed.org/users/mbed_official/code/mbed-src/file/1c287fe42d43/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/TARGET_FRDM/PeripheralPins.c, if you select two SPI ports which use different SPI peripherals it should work fine.

Accepted Answer

Thank you Erik! I just verified that PTE1 and PTD7 correspond both to the MISO line of SPI1:

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},
    {PTB23, SPI_2, 2},
    {PTC7 , SPI_0, 2},
    {PTD7 , SPI_1, 7},
    {NC   , NC   , 0}
};

Could I ask you how can I redirect those pins to different SPI units in my program? Should I export the program to my PC and modify the PeriperalPins.c source code?

Thank you for your support.

Regards.

posted by Francesco Adamo 08 Sep 2014

That is sadly not possible, it is simply how the microcontroller is hardwired. You will need to use different pins, such that they do not use the same SPI peripheral, or you need to make them use exactly the same pins, that should work correctly too.

If you really need to use those same SPI peripherals it is possible to manually set which pins it should use before every SPI transaction, although using different SPI peripherals is easier.

But if you really need to use those pins, the following code should work (I assume here that only the MISO line is the issue, since that is the case for NXP microcontrollers, but not 100% sure it will be the same here). You need to do these everytime you switch which device you use:

Before using SD:

pin_function(SD_MISO, 7);  //Set SD_MISO as SPI, this is the same as the last number in those tables
pin_function(NRF_MISO, 1); //pin function 1 is GPIO

And before using NRF:

pin_function(SD_MISO, 1);  
pin_function(NRF_MISO, 7); 
posted by Erik - 08 Sep 2014

Thank you again Erik! I think that the solution you propose is the only one I can use... I will make some experiments and I hope that the resulting write speed on the SD-CARD is sufficient for my needs.

Regards.

posted by Francesco Adamo 08 Sep 2014