M5Stack + NRF24 = LCD slow down
-
Hi!
I'm using a M5Stack Gray, with a NRF24L01 radio transmitter.#include <M5Stack.h> #include <RF24.h> //------------------------------------- Radio RF24 #define rf24CePin 16 #define rf24CsnPin 17 RF24 RF24(rf24CePin, rf24CsnPin);
As soon as I invoke a RF24 function like RF24.available() or RF24.printDetails(), the LCD display of the M5Stack slows down dramatically.
At the start, the SPI BUS of the M5Stak is at 40mHz (In_eSPI_Setup.h #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS), it seems to me that it falls below 1mHz.
Why?Thanks for your help
cordially
jpbbricole -
Hi
I found the reason for the slowdown of the LCD display, it's in RF24-master library, file RF24.cpp.#elif F_CPU < 320000000 _SPI.setClockDivider(SPI_CLOCK_DIV32);
As the speed of the M5Stack is 24000000, that divided the frequency of the SPI by 32.
I added#elif F_CPU == 240000000 // For M5Stack Grey _SPI.setClockDivider(SPI_CLOCK_DIV2); // For M5Stack Grey
and the problem is solved.
Thanks for reading me
cordially
jpbbricole -
Glad you found the issue. I’m interested in seeing your full code once you have it done. I’m also interested in using the NRF24L01 in a project idea that I have been thinking of.
-
Hi world101
To make this modification, I determined the speed of the M5Stack by making a program with:
Serial.println (F_CPU)
which gave 24000000
Then, I modified the file ..\libraries\RF24-master\RF24.cpp by adding these lines (who have // For M5Stack Gray as a remark)
#if !defined(SOFTSPI) _SPI.setBitOrder(MSBFIRST); _SPI.setDataMode(SPI_MODE0); #if !defined(F_CPU) || F_CPU < 20000000 _SPI.setClockDivider(SPI_CLOCK_DIV2); #elif F_CPU < 40000000 _SPI.setClockDivider(SPI_CLOCK_DIV4); #elif F_CPU < 80000000 _SPI.setClockDivider(SPI_CLOCK_DIV8); #elif F_CPU < 160000000 _SPI.setClockDivider(SPI_CLOCK_DIV16); #elif F_CPU == 240000000 // For M5Stack Grey _SPI.setClockDivider(SPI_CLOCK_DIV2); // For M5Stack Grey** #elif F_CPU < 320000000 _SPI.setClockDivider(SPI_CLOCK_DIV32); #elif F_CPU < 640000000 _SPI.setClockDivider(SPI_CLOCK_DIV64); #elif F_CPU < 1280000000 _SPI.setClockDivider(SPI_CLOCK_DIV128); #else #error "Unsupported CPU frequency. Please set correct SPI divider." #endif #endif
Regarding the program where I use the RF24, it is very large, I can, if you want, give you an example of use, with several pipes.
cordially
jpbbricole