http://www.stm32duino.com/viewtopic.php … 7&start=30
I think this library also worked well with STM32F4 discovery board, but as soon as I declare
RF24 radio(PA3,PA4)
Cheers, Ollie
post a link to the board, although i suspect which one it is. i’ve 2 with a socket.
check the wiki
also this line intrigues me
#include <../../libraries/RF24/RF24.h>
#include<RF24.h>
#include<RF24Network.h>
#include<SPI.h>
#include <DHT.h>
#define DHTPIN PC0
#define DHTTYPE DHT11 // DHT 11
#define DHTPIN PC0
DHT dht(DHTPIN, DHTTYPE);
// Radio with CE & CSN connected to pins PB0 & PB1
// Set up nRF24L01 radio on SPI-1 bus (MOSI-PA7, MISO-PA6, SCLK-PA5) ... IRQ not used?
HardwareSerial Myboard(USART1,PB6,PB7);
HardwareSPI SPI(1);
const uint64_t pipes[2] = { 0xCCCCCCCC3C, 0xCCCCCCCCC3 };
RF24 radio(PB0,PB1);
RF24Network network(radio);
const uint16_t this_node = 1;
const uint16_t parent_node = 0;
const unsigned long interval = 1000; // every sec
struct payload_t { // Structure of our payload
unsigned long node;
byte DHT11temp;
byte DHT11hum;
};
// Structure of our message
struct message_1 {
float temperature;
float humidity;
};
message_1 message;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup() {
Myboard.begin(19200);
SPI.begin();
pinMode(PD13, OUTPUT);
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
radio.setChannel(0x4c);
radio.setPALevel(RF24_PA_MAX);
// Open pipes to other nodes for communication
// This simple sketch opens two pipes for these two nodes to communicate
// back and forth.
// Open 'our' pipe for writing
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
// Start listening
radio.startListening();
// Dump the configuration of the rf unit for debugging
radio.printDetails();
delay(50);
network.begin(90, this_node);
// Initialize the DHT library
// Initialize the DHT library
dht.begin();
delay(50);
}
void loop() {
payload_t packet;
byte h = dht.readHumidity();
//Read temperature as Celsius
byte t = dht.readTemperature();
// Construct the message we'll send
message = (message_1){t,h};
// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';
digitalWrite(PD13, HIGH);
Myboard.println("HIGH");
delay(1000);
// Update network data
network.update();
// Writing the message to the network means sending it
if (network.write(header, &message, sizeof(message))) {
Myboard.print("Temp = "); Myboard.println(t);
Myboard.print("Humid = "); Myboard.println(h);
} else {
Myboard.print("Could not send message\n");
}
digitalWrite(PD13, LOW);
Myboard.println("LOW");
delay(1000);
// Wait a bit before we start over again
delay(interval);
}
I think the RF24Network library I used has some bugs with STM32F4 disc board!
Any suggestion?
The whole code:
#include<RF24.h>
#include<RF24Network.h>
#include<SPI.h>
#include <DHT.h>
#define DHTPIN PC0
#define DHTTYPE DHT11 // DHT 11
#define DHTPIN PC0
DHT dht(DHTPIN, DHTTYPE);
// Radio with CE & CSN connected to pins PB0 & PB1
// Set up nRF24L01 radio on SPI-1 bus (MOSI-PA7, MISO-PA6, SCLK-PA5) ... IRQ not used?
HardwareSerial Myboard(USART1,PB6,PB7);
HardwareSPI MySPI(1);
const uint64_t pipes[2] = { 0xCCCCCCCC3C, 0xCCCCCCCCC3 };
RF24 radio(PB0,PB1);
RF24Network network(radio);
const uint16_t this_node = 1;
const uint16_t parent_node = 0;
const unsigned long interval = 1000; // every sec
struct payload_t { // Structure of our payload
unsigned long node;
byte DHT11temp;
byte DHT11hum;
};
// Structure of our message
struct message_1 {
float temperature;
float humidity;
};
message_1 message;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup() {
Myboard.begin(19200);
MySPI.begin(SPI_9MHZ,MSBFIRST,SPI_MODE0);
pinMode(PD13, OUTPUT);
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
radio.setChannel(0x4c);
radio.setPALevel(RF24_PA_MAX);
// Open pipes to other nodes for communication
// This simple sketch opens two pipes for these two nodes to communicate
// back and forth.
// Open 'our' pipe for writing
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
// Start listening
radio.startListening();
// Dump the configuration of the rf unit for debugging
radio.printDetails();
delay(50);
network.begin(90, this_node);
// Initialize the DHT library
// Initialize the DHT library
dht.begin();
delay(50);
}
void loop() {
payload_t packet;
byte h = dht.readHumidity();
//Read temperature as Celsius
byte t = dht.readTemperature();
// Construct the message we'll send
message = (message_1){t,h};
// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';
digitalWrite(PD13, HIGH);
Myboard.println("HIGH");
delay(1000);
// Update network data
network.update();
// Writing the message to the network means sending it
// if (network.write(header, &message, sizeof(message))) {
// Myboard.print("Temp = "); Myboard.println(t);
// Myboard.print("Humid = "); Myboard.println(h);
// } else {
// Myboard.print("Could not send message\n");
// }
digitalWrite(PD13, LOW);
Myboard.println("LOW");
delay(1000);
// Wait a bit before we start over again
delay(interval);
}
2. If the LED is ON when PD13 is “LOW”, then your problem is actually the “Myboard.print()” function. And this, as I mentioned before, it may has to do with one of the latest commits in the repository (from xymopen), which introduces some problems. In this case I would recommend you to use this version, the version of the repository before the problematic commit. Just download and extract the ZIP, as usual.
This is exactly my board,I’ll try your suggestion, glad that you answered me,
Thanks
EDIT: what do you mean by “use millis() to provide something as data to write to the radio.”? Can you write down the specific command to implement what you said?

the logic behind removing the dht aspects and using millis is building blocks is that millis is a known and easily testable function, Serial.println(millis());
removing the dht aspect temporarily is to remove a potential problem. solve that by using their example as a test of dht.
using millis you can just create a packet structure with counter and millis as long int fields.
the dht example code i think converts the values to an ascii string for printing, but you could send the raw values as a field.
there’s getting started sending data example from rf24, essentially using notionally ‘good’ code.
combine the two sketches as a third and adapt.
a long time ago, my maths teacher was happy i was 3, 4 or 5 chapters worth ahead in the exercises, but not that everyone else got the same solutions.
mind you, he objected when i worked each side of ‘prove this equals that trig equation’ exercises. one forward, other backward until they met, 1==1 or 1 == 0 oops. i still don’t follow why.
stephen

Now things are totally a mess, I hope anyone could help me write a code to transmit/receive data using nrf24l01 with stm32f4 discovery . Because there are so many conflicts in using the libraries provided by previous authors in this forum
i’ll go looking for it
stephen
Hey Manny, can you show me specifically how can I get it work?
Here’s what I did:
+ Commented out network.update(), because this line makes my code stuck!
+ I used the SPI library from here : https://github.com/rogerclarkmelbourne/Arduino_STM32 (in STM32F4/libraries/SPI) – I cut and paste it in the path: C:\Users\ASUS\Documents\Arduino\libraries\
+ I used the DHT library from here: https://github.com/markruys/arduino-DHT
+ And the RF24Network library from here: https://github.com/maniacbug/RF24Network
+ The RF24 library from here: http://www.stm32duino.com/viewtopic.php … =30#p11251 (the last comment of this link)
My code now:
#include "nRF24L01.h"
#include <RF24Network.h>
#include <RF24.h>
#include <C:\Users\ASUS\Documents\Arduino\libraries\SPI\src\SPI.h>
#include "DHT.h";
DHT dht;
HardwareSerial Myboard(USART1,PB6,PB7);
// Set up nRF24L01 radio on SPI-1 bus (MOSI-PA7, MISO-PA6, SCLK-PA5) ... IRQ not used?
RF24 radio(PB0,PB1);
RF24Network network(radio);
const uint64_t pipes[2] = {0xCCCCCCCC3C, 0xCCCCCCCCC3}; // Radio pipe addresses for the 2 nodes to communicate.
// Constants that identify this node and the node to send data to
const uint16_t this_node = 1;
const uint16_t parent_node = 0;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup() {
// put your setup code here, to run once:
pinMode(PD13, OUTPUT);
Myboard.begin(115200);
dht.setup(PC0);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin();
network.begin(90, this_node);
radio.setRetries(15,15);
radio.setChannel(0x4c);
radio.setAutoAck(false);
radio.setDataRate(RF24_1MBPS);
radio.setCRCLength(RF24_CRC_16);
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.printDetails();
}
void loop() {
// Update network data
//network.update();
delay(dht.getMinimumSamplingPeriod());
float h = dht.getHumidity();
float t = dht.getTemperature();
header.type = '1';
// Construct the message we'll send
struct message_1 {
float temperature;
float humidity;
};
message_1 message;
radio.setPayloadSize(sizeof(message));
message = (message_1){ t, h };
digitalWrite(PD13, HIGH);
Myboard.println("HIGH");
delay(1000);
radio.powerUp();
delay(1);
radio.stopListening();
delay(1);
bool ok = network.write(header,&message,sizeof(message));
if (ok)
Myboard.println("Send Ok.");
else
Myboard.println("Send Failed.");
digitalWrite(PD13, LOW);
Myboard.println("LOW");
delay(1000);
}
STATUS = 0x0E RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xCC 0xCC 0xCC 0x3C 0xCC 0xCC 0xCC 0xCC 0x3C 0x3C
RX_ADDR_P2-5 = 0x33 0xCE 0x3E 0xE3
TX_ADDR = 0xE7 0xE7 0xE7 0xE7 0xE7
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3E
EN_RXADDR = 0x3F
RF_CH = 0x3C
RF_SETUP = 0x27
CONFIG = 0x0F
DYNPD/FEATURE = 0x3F 0x04
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
STATUS = 0x0E RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xCC 0xCC 0xCC 0x3C 0xCC 0xCC 0xCC 0xCC 0x3C 0x3C
RX_ADDR_P2-5 = 0x33 0xCE 0x3E 0xE3
TX_ADDR = 0xE7 0xE7 0xE7 0xE7 0xE7
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3E
EN_RXADDR = 0x3F
RF_CH = 0x3C
RF_SETUP = 0x27
CONFIG = 0x0F
DYNPD/FEATURE = 0x3F 0x04
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
Sorry don’t have a F4 to try out.

+ I used the SPI library from here : https://github.com/rogerclarkmelbourne/Arduino_STM32 (in STM32F4/libraries/SPI) – I cut and paste it in the path: C:\Users\ASUS\Documents\Arduino\libraries\
it shouldn’t be looking there at all, is there a quirk with f4 spi?
stephen
it at first flagged missing library maintainer, add fred also added [email protected] for the email
thought i’d add it in, did, tried re-compile, same of course (i knew that honest

then it gave up with
In file included from /home/stephen/sketchbook/Blinki2c/Blinki2c.ino:19:0:
/home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/libraries/SPI/src/SPI.h:362:17: error: conflicting declaration 'SPIClass SPI'
extern SPIClass SPI;//(1);// dummy params
^
In file included from /home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/cores/maple/wirish.h:49:0,
from /home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/cores/maple/WProgram.h:27,
from /home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/cores/maple/Arduino.h:3,
from /tmp/arduino_build_22323/sketch/Blinki2c.ino.cpp:1:
/home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/HardwareSPI.h:276:20: error: 'SPI' has a previous declaration as 'HardwareSPI SPI'
extern HardwareSPI SPI;
^
Using library SPI at version 1.0 in folder: /home/stephen/sketchbook/hardware/Arduino_STM32/STM32F4/libraries/SPI
exit status 1
Error compiling for board STM32 Discovery F407.
http://www.stm32duino.com/viewtopic.php … eSPI#p9227
Just simply comment out the line extern HardwareSPI … in your HardwareSPI.h file. If I recall correctly, this file is under …\STM32F4\cores\maple\libmaple
Comment out all the SPI code in your sketch you just need to #include <SPI.h> and SPI.begin() in set up.
Another thing I noticed is you’re using SPIClass(3) which on the STM32F1 that I’m using shares the pins with JTAG debug, to get round this you will need to put disableDebugPorts() in setup. Not sure if this effects the F4 but it wouldn’t hurt to try it.
disableDebugPorts();
The number of SPI pins is actually able to change in my program, so as you said, I changed it to SPIClass MySPI(1). That’s means I dont have to use your disable port command
I copied your lib under the folder hardware\Arduino_STM32..\STM32F4\libraries
I also changed the #include “RF24.h” inside RF24Network.h to #include “RF24_STM32.h” so that it fits your lib.
#include<C:\Users\ASUS\Documents\Arduino\hardware\Arduino_STM32-7985f25fbcb06f7a38f55d84cdf4b0b58e72da11\STM32F4\libraries\RF24_STM32\RF24_STM32.h>
#include<C:\Users\ASUS\Documents\Arduino\hardware\Arduino_STM32-7985f25fbcb06f7a38f55d84cdf4b0b58e72da11\STM32F4\libraries\RF24Network-master\RF24Network.h>
#include <C:\Users\ASUS\Documents\Arduino\hardware\Arduino_STM32-7985f25fbcb06f7a38f55d84cdf4b0b58e72da11\STM32F4\libraries\SPI\src\SPI.h>
#include <C:\Users\ASUS\Documents\Arduino\hardware\Arduino_STM32-7985f25fbcb06f7a38f55d84cdf4b0b58e72da11\STM32F4\libraries\DHT-sensor-library-master\DHT.h>;
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
HardwareSerial Myboard(USART1,PB6,PB7);
SPIClass MySPI(1);
// Radio with CE & CSN connected to pins 7 & 8
RF24 radio(PB0, PB1);
RF24Network network(radio);
const uint64_t pipes[2] = {0xCCCCCCCC3C, 0xCCCCCCCCC3}; // Radio pipe addresses for the 2 nodes to communicate.
// Constants that identify this node and the node to send data to
const uint16_t this_node = 1;
const uint16_t parent_node = 0;
struct message_1 {
float temperature;
float humidity;
};
message_1 message;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup() {
// put your setup code here, to run once:
pinMode(PD13, OUTPUT);
Myboard.begin(115200);
// Initialize the DHT library
dht.begin();
// Initialize all radio related modules
MySPI.begin();
radio.setRetries(15,15);
radio.setChannel(0x4c);
radio.setAutoAck(false);
radio.setPayloadSize(sizeof(message));
radio.setCRCLength(RF24_CRC_16);
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.begin();
delay(5);
network.begin(90, this_node);
radio.printDetails();
}
void loop() {
// Update network data
network.update();
// Read humidity (percent)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';
// Construct the message we'll send
message = (message_1){ t, h };
digitalWrite(PD13, HIGH);
Myboard.println("HIGH");
delay(1000);
bool ok = network.write(header,&message,sizeof(message));
if (ok)
Myboard.println("Send Ok.");
else
Myboard.println("Send Failed.");
digitalWrite(PD13, LOW);
Myboard.println("LOW");
delay(1000);
}
Comment out all the SPI code in your sketch you just need to #include <SPI.h> and SPI.begin() in set up.
Another thing I noticed is you’re using SPIClass(3) which on the STM32F1 that I’m using shares the pins with JTAG debug, to get round this you will need to put disableDebugPorts() in setup. Not sure if this effects the F4 but it wouldn’t hurt to try it.
disableDebugPorts();
How to assign this library to SPI3 ?
A special socket for the nRF24L01 on the Board STM32F407VET6 BLACK
[acronis – Thu Jul 27, 2017 8:17 am] –
How to assign this library to SPI3 ?
SPIClass mSPI(3);
Please tell me how to fix the following example for SPI3 STM32F407VET6 to work on SPI3
/*
Sensor Receiver.
Each sensor modue has a unique ID.
TMRh20 2014 - Updates to the library allow sleeping both in TX and RX modes:
TX Mode: The radio can be powered down (.9uA current) and the Arduino slept using the watchdog timer
RX Mode: The radio can be left in standby mode (22uA current) and the Arduino slept using an interrupt pin
*/
#include <SPI.h>
#include "nRF24L01_STM32.h"
#include "RF24_STM32.h"
// Set up nRF24L01 radio on SPI-1 bus (MOSI-PA7, MISO-PA6, SCLK-PA5) ... IRQ not used?
RF24 radio(PB0,PB1);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; // Radio pipe addresses for the 2 nodes to communicate.
struct payload_t { // Structure of our payload
unsigned long node;
unsigned long counter;
float DHT11temp;
float DHT11hum;
int batteryLevel;
};
void setup(){
Serial.begin(9600);
delay(1000);
Serial.println("\n\rRF24 Sensor Receiver");
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
// Setup and configure rf radio
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
radio.setChannel(0x4c);
radio.setPALevel(RF24_PA_LOW);
// Open pipes to other nodes for communication
// This simple sketch opens two pipes for these two nodes to communicate
// back and forth.
// Open 'our' pipe for writing
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
// Start listening
radio.startListening();
// Dump the configuration of the rf unit for debugging
radio.printDetails();
}
void loop(){
payload_t packet;
// Receive each packet, dump it out
if ( radio.available() ) { // if there is data ready
radio.read( &packet, sizeof(packet) ); // Get the payload, and see if this was the last one.
Serial.print("Received from Sensor: "); Serial.print(packet.node);
Serial.print(" #:"); Serial.println(packet.counter);
Serial.print("DHT11 Temp = "); Serial.print(packet.DHT11temp);
Serial.print(" DHT11 Humidity = "); Serial.print(packet.DHT11hum);
Serial.print(" Batt = "); Serial.println((float)packet.batteryLevel/(float)266.7);
}
}
RF24 radio(PB0,PB1);
In the examples written by different pins .
What should I specify ?
RF24 radio(CE_PIN, CSN_PIN); ???
RF24 radio(PB6, PB7 );
So right ?
[acronis – Thu Jul 27, 2017 9:02 am] –
RF24 radio(CE_PIN, CSN_PIN); ???
RF24 radio(PB6, PB7 );
So right ?
It seems so.
Btw, have you seen this lib? https://github.com/jaretburkett/RF24-STM
RF24 radio(PB6, PB7 );
This library works on STM32F407VET6.
Thank you all.
the question is closed
It’s not my topic and not my first post,
I don’t know how to add a message.
Tell me what you need and how to do it.
You can’t do that.
I thought as you indicated it worked and you said “Thank you all. ” you must have started the tread
On the OP (and I ) can change the thread title and its best if the OP does that