nRF24l01 on Bluepill

Any other microcontroller based boards
hierophect
Posts: 14
Joined: Tue Mar 12, 2019 10:17 pm

nRF24l01 on Bluepill

Post by hierophect » Thu Mar 14, 2019 3:44 pm

I've been attempting to get the nRF24l01 working on my bluepills for a small networked project. So far, the only library I've found that is properly compatible with the new ST core was this old library dropped as a .zip in a discussion by "madias":
https://www.stm32duino.com/viewtopic.ph ... e&start=40
All other attempts, have proven fruitless, usually due to failing to utilize the new ST core serial print integration or otherwise not being compatible with Bluepill SPI. I've also had no success in porting the library myself, probably as I'm not an expert in the requirements of porting code to STM32Duino, at least not right now with all this confusion about features and compatibility as the community transfers from Roger's core to the ST one. Some systems that I tried and failed include:
- Core library to port, not expected to work on STM32: https://github.com/TMRh20
- changing it myself to support STM32: http://www.stm32duino.com/viewtopic.php?f=15&t=317
- this 2017 library (does not compile at all) https://github.com/markkharkov/RF24
- fails silently: https://github.com/spirilis/Enrf24

However, this currently library seems to be working... mostly. I'm still not getting successful data transfers. Both boards have had their SPI tested and are successfully connected to their NRF chips. My transmitter seems to be working ok, and I know it detects the receiver because it returns a couple of "acknowledge" confirmations right when the other board is turned on. But the receiver doesn't ever confirm that it receives any data at any point, and the transmitter stops showing acknowledge messages after about 4 seconds.

I was hoping someone else might have dealt with this system before. Or, perhaps, could put me in touch with madias on the old forum so I could ask him whether he still has any interest in maintaining this code or adding it to github, as it seems to be literally the only working STM32duino code that exists online.

Code, for reference:

TX

Code: Select all

// SimpleTx - the master or the transmitter

#include <SPI.h>
#include "nRF24L01_STM32.h"
#include "RF24_STM32.h"

RF24 radio(PB1,PB0);

const uint64_t pipe = 0xF0F0F0F0E1LL;

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);
    SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setRetries(15,15);
    radio.setChannel(0x4c);
    //radio.setPALevel(RF24_PA_LOW);
    radio.setDataRate( RF24_250KBPS );
    radio.openWritingPipe(pipe);
    radio.printDetails();
//    radio.setDataRate( RF24_250KBPS );
//    radio.setRetries(3,5); // delay, count
//    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}
RX

Code: Select all


// SimpleRx - the slave or the receiver

#include <SPI.h>
#include "nRF24L01_STM32.h"
#include "RF24_STM32.h"

RF24 radio(PB1,PB0);

const uint64_t pipe = 0xF0F0F0F0E1LL;

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup() {
    Serial.begin(9600);
    delay(1000);
    SPI.begin();
    SPI.setDataMode(SPI_MODE0);
    SPI.setBitOrder(MSBFIRST);

    Serial.println("SimpleRx Starting");
    
    radio.begin();
    radio.setChannel(0x4c);
    //radio.setPALevel(RF24_PA_LOW);
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1,pipe);
    radio.startListening();
    //radio.printDetails();
//    radio.setDataRate( RF24_250KBPS );
//    radio.openReadingPipe(1, thisSlaveAddress);
//    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
        Serial.print("HIT");
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    } else {
        Serial.print("No Data");
        delay(200);
    }
}
OS IDE Core Board
[ ] Windows
[ ] Linux
[x] Mac OS
[x] Arduino 1.8.8
[ ] PlatformIO
[ ] Sloeber
[ ] Roger's
[x] STM
[ ] Else
[x] Blue pill
[x] Custom F103
[ ] Black pill

hierophect
Posts: 14
Joined: Tue Mar 12, 2019 10:17 pm

Re: nRF24l01 on Bluepill

Post by hierophect » Thu Mar 14, 2019 4:51 pm

Welp, figured it out.

Hey kids! Did you know that Serial can not only halt your entire program, it can also change your variables? That's right, it's very dangerous! Use a real debugger instead!

Had to have both boards on an active serial line, otherwise they would not transmit. I've been using LCDs and MBED's non-blocking serial libraries too much I suppose.

Anyway, I would appreciate being able to put this stuff on Github, does anyone know madias from the old forum?
OS IDE Core Board
[ ] Windows
[ ] Linux
[x] Mac OS
[x] Arduino 1.8.8
[ ] PlatformIO
[ ] Sloeber
[ ] Roger's
[x] STM
[ ] Else
[x] Blue pill
[x] Custom F103
[ ] Black pill

User avatar
zoomx
Posts: 52
Joined: Tue Mar 05, 2019 8:10 am
Location: Mt Etna - Italy
OS: Windows 7 & 10
IDE: 1.8.8
Core: Roger & STM official
Board: Bluepill, Maple mini

Re: nRF24l01 on Bluepill

Post by zoomx » Fri Mar 15, 2019 7:51 am

hierophect wrote:
Thu Mar 14, 2019 4:51 pm
Hey kids! Did you know that Serial can not only halt your entire program, it can also change your variables?
:shock:

stevestrong
Posts: 75
Joined: Tue Mar 05, 2019 7:49 am
Location: Munich
OS: Win7 & 10
IDE: Arduino 1.8.8, Sloeber
Core: Libmaple
Board: Bluepill, Generic F4VET6 black & mini
Contact:

Re: nRF24l01 on Bluepill

Post by stevestrong » Fri Mar 15, 2019 12:19 pm

I think this thread should be moved under "STM core"

User avatar
BennehBoy
Posts: 67
Joined: Tue Mar 05, 2019 7:43 pm
Location: Yorkshire
OS: Windows 10
IDE: 1.8.9, Sloeber
Core: Roger's & STM
Board: Blue/Blackpill, MM, HYTiny, Black407Z/VET6, DiyMroe, FK407M1
Contact:

Re: nRF24l01 on Bluepill

Post by BennehBoy » Fri Mar 15, 2019 12:27 pm

hierophect wrote:
Thu Mar 14, 2019 4:51 pm
Anyway, I would appreciate being able to put this stuff on Github, does anyone know madias from the old forum?
I've Pm'd him on the old forum..
-Ben

hierophect
Posts: 14
Joined: Tue Mar 12, 2019 10:17 pm

Re: nRF24l01 on Bluepill

Post by hierophect » Fri Mar 15, 2019 5:28 pm

BennehBoy wrote:
Fri Mar 15, 2019 12:27 pm
Board index
Thanks, hopefully can post more use cases/information soon as I progress.
stevestrong wrote:
Fri Mar 15, 2019 12:19 pm
I think this thread should be moved under "STM core"
Wasn't sure where to put a topic related to external peripheral libraries for the core. If that's a better spot I'm all for it.
OS IDE Core Board
[ ] Windows
[ ] Linux
[x] Mac OS
[x] Arduino 1.8.8
[ ] PlatformIO
[ ] Sloeber
[ ] Roger's
[x] STM
[ ] Else
[x] Blue pill
[x] Custom F103
[ ] Black pill

User avatar
BennehBoy
Posts: 67
Joined: Tue Mar 05, 2019 7:43 pm
Location: Yorkshire
OS: Windows 10
IDE: 1.8.9, Sloeber
Core: Roger's & STM
Board: Blue/Blackpill, MM, HYTiny, Black407Z/VET6, DiyMroe, FK407M1
Contact:

Re: nRF24l01 on Bluepill

Post by BennehBoy » Fri Mar 15, 2019 5:33 pm

This search turns up a few that could be the same as above....

https://github.com/search?q=nrf24+hal
-Ben

hierophect
Posts: 14
Joined: Tue Mar 12, 2019 10:17 pm

Re: nRF24l01 on Bluepill

Post by hierophect » Fri Mar 15, 2019 5:46 pm

But returning to the serial issue, am I being a huge idiot with my Serial code? I wasn't under the impression that Serial.printf was blocking if there isn't an active connection to the computer. It sure isn't on mbed, and I don't think I've had this happen on my usual Arduino boards before, but maybe I'm out of my depth. If there's documentation on this that I can read through please let me know.
OS IDE Core Board
[ ] Windows
[ ] Linux
[x] Mac OS
[x] Arduino 1.8.8
[ ] PlatformIO
[ ] Sloeber
[ ] Roger's
[x] STM
[ ] Else
[x] Blue pill
[x] Custom F103
[ ] Black pill

User avatar
BennehBoy
Posts: 67
Joined: Tue Mar 05, 2019 7:43 pm
Location: Yorkshire
OS: Windows 10
IDE: 1.8.9, Sloeber
Core: Roger's & STM
Board: Blue/Blackpill, MM, HYTiny, Black407Z/VET6, DiyMroe, FK407M1
Contact:

Re: nRF24l01 on Bluepill

Post by BennehBoy » Fri Mar 15, 2019 6:42 pm

I'm not sure about whether it blocks tbh - I've not played about with it enough. All I know about is the buffer issue which is resolved in a PR that just got merged - perhaps a question for @fpistm.
-Ben

User avatar
MoDu
Posts: 69
Joined: Tue Mar 05, 2019 1:56 pm
Location: Lisbon
OS: Windows
IDE: Visual Studio
Core: Roger's
Board: Maple mini

Re: nRF24l01 on Bluepill

Post by MoDu » Fri Mar 22, 2019 10:08 am

It does block (on roger's core), I've noticed this behaviour consistently. It's not like an AVR, where the serial output is just lost.
I've yet to try the new version.

Post Reply