[SOLVED] STM32F4 +RF24 library problem

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
41300895
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

[SOLVED] STM32F4 +RF24 library problem

Post by 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

Code: Select all

RF24 radio(PA3,PA4)

My code seems to be unactivated.If I delete it, my code worked.
All I want is that my PD13 led could blink as in the loop() function said, please help me figure out what's going on?

Code: Select all

#include <../../libraries/RF24/RF24.h>
#include <DHT.h>
#define DHTPIN PC0
#define DHTTYPE DHT11   // DHT 11
#define DHTPIN PC0
DHT dht(DHTPIN, DHTTYPE);
// Set up nRF24L01 radio on SPI-1 bus (MOSI-PA7, MISO-PA6, SCLK-PA5) ... IRQ not used?
RF24 radio(PA3,PA4);
HardwareSerial Myboard(USART1,PB6,PB7);
HardwareSPI MySPI(1);
const uint64_t pipes[2] = { 0xCCCCCCCC3C, 0xCCCCCCCCC3 };
const unsigned long interval = 1000;  // every sec
struct payload_t {                  // Structure of our payload
  unsigned long node;
  byte DHT11temp;
  byte DHT11hum;
}
void setup() {
  Myboard.begin(19200);
  MySPI.begin(SPI_9MHZ,MSBFIRST,0);
  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);
  dht.begin();
  delay(50);
}

void loop() {
  digitalWrite(PD13, HIGH);
  Myboard.print("HIGH");
  delay(1000);
  digitalWrite(PD13, LOW);
  Myboard.print("LOW");
  delay(1000);
  // Wait a bit before we start over again
  delay(interval);
}

I am very appreciated if anyone can pinpoint my problem
Sincerely,
p.s: When I said "unactivated", I mean I compiled and uploaded successfully but my PD13 led couldn't blink at all :(

Ollie
Posts: 188
Joined: Thu Feb 25, 2016 7:27 pm

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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
Posts: 1417
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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

Code: Select all

#include <../../libraries/RF24/RF24.h>
i can't recall ever seeing
#include <../../libraries/
in a sketch before, so please detail your setup and
also add full output for compile/upload.

stephen

41300895
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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:

Code: Select all

#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 used STM32duino library from this link: https://github.com/rogerclarkmelbourne/Arduino_STM32.
And the RF24 library from the link I had posted.
the RF24Network from this github link: https://github.com/maniacbug/RF24Network.

I put nrf24l01.h RF24.cpp RF24.h RF24_config.h RF24Network.cpp RF24Network.h RF24Network_config.h (without any change) in the same folder called RF24 (this is the path on my PC: C:\Users\ASUS\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\RF24 ).
Please help,
sincerely,
p.s: the blinky example works fine!

zmemw16
Posts: 1417
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Please help!!! STM32F4 +RF24 library problem

Post by zmemw16 » Mon Nov 07, 2016 4:23 pm

what does
radio.printDetails();
give?

stevestrong
Posts: 1608
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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:

Code: Select all

#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
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

Re: Please help!!! STM32F4 +RF24 library problem

Post by 41300895 » Sat Nov 12, 2016 12:30 am

Anyone could help me pls?

stevestrong
Posts: 1608
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Please help!!! STM32F4 +RF24 library problem

Post by 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.

Post Reply