Spark Logic

[SOLVED] STM32F4 +RF24 library problem

41300895 Sun Nov 06, 2016 11:31 am

I am using the library from this thread (uploaded by jbforrer – you can see his comment at the bottom):
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)

Replies

Ollie Sun Nov 06, 2016 4:35 pm

Sorry, I don’t have an answer for you, but only a friendly feedback. It is annoying to have the same message posted in 3 different places.

Cheers, Ollie

41300895 Sun Nov 06, 2016 5:32 pm

sorry, I was confused did not know where to post, so I posted any forum relevant, really apologize for annoying you

zmemw16 Mon Nov 07, 2016 10:58 am

does pd13 blink in the blinky sketch?
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>

41300895 Mon Nov 07, 2016 1:14 pm

As your suggestion, I deleted the path ../../library/.. and I compiled + uploaded successfully, now my led is blinking but there is another problem. It seems that my code is stuck at the line network.update (If i add this line, the pd13 led always HIGH, but when I comment it out, PD13 led blinks again) here is the 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 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);
}

zmemw16 Mon Nov 07, 2016 4:23 pm

what does radio.printDetails(); give?

stevestrong Mon Nov 07, 2016 5:03 pm

I am not sure, but I think the latest print class seems to be problematic, I also had to revert locally those changes in order to avoid some .print() related issues.

41300895 Mon Nov 07, 2016 5:39 pm

NOW this is getting weird now, after hours of editting, I realized the line” network.update() makes my code stuck because the pd13 led always ON. If I remove it, the PD13 led blinks normally.
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);
}

41300895 Sat Nov 12, 2016 12:30 am

Anyone could help me pls?

stevestrong Sat Nov 12, 2016 8:19 am

1. Are you sure that the LED is on when PD13 is “HIGH”? Because more often the LEDs are driven with “LOW” signals.
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.

zmemw16 Sat Nov 12, 2016 12:43 pm

41300895 wrote:NOW this is getting weird now, after hours of editing, I realized the line” network.update() makes my code stuck because the pd13 led always ON. If I remove it, the PD13 led blinks normally.

zmemw16 Sun Nov 13, 2016 7:37 am

zmemw16 wrote:41300895 wrote:NOW this is getting weird now, after hours of editing, I realized the line” network.update() makes my code stuck because the pd13 led always ON. If I remove it, the PD13 led blinks normally.

41300895 Sun Nov 13, 2016 9:44 am

https://www.google.com.vn/search?q=stm3 … KflCetM%3A
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?

zmemw16 Sun Nov 13, 2016 8:52 pm

well the schematic isn’t going to be a problem to find. its in the user guide :D

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

41300895 Mon Nov 14, 2016 2:45 pm

Still no luck :(
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

zmemw16 Mon Nov 14, 2016 3:10 pm

pretty sure i’ve a 407 discovery somewhere .. ..
i’ll go looking for it

stephen

Manny Mon Nov 14, 2016 6:03 pm

I use this RF24 library that was attached to this post RF24_STM32 with RF24Network from Here I think it needed some minor commenting out to get it to compile.

41300895 Wed Nov 23, 2016 5:44 am

thanks for your both dedication!
Hey Manny, can you show me specifically how can I get it work?

41300895 Wed Nov 23, 2016 3:42 pm

I’ve managed to get things better a little bit!
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);
}

Manny Thu Nov 24, 2016 5:18 pm

This is what radio.printdetails outputs on my STM32F1

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

41300895 Thu Nov 24, 2016 6:24 pm

Manny wrote:This is what radio.printdetails outputs on my STM32F1

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

Sign in to reply