Please help!!! 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

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

Postby 41300895 » Sun Nov 27, 2016 1:45 pm

Dear Manny,
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.

Code: Select all

#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);
}

But at the moment I don't have STM32F4 disc board on my side, I will fetch it right away to check if it works or not
So if anyone pleased, can upload my code and check whether my code works or crashes down (the simplest way is to check the result of radio.printDetails() and the PD13 led (does it blink?) ) in the mean time.

klerone
Posts: 7
Joined: Fri Mar 24, 2017 2:49 am

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

Postby klerone » Tue Mar 28, 2017 2:04 am

Manny wrote:Try the library attached, I hacked it so the the SPIclass is defined in line 13 of RF24_STM32.cpp, I find it easier to do that way, you just got to remember to change the class if you're using different SPI pins.

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.

Code: Select all

disableDebugPorts();


Great Job man! thank you.


Return to “STM32F4 Boards”

Who is online

Users browsing this forum: martinayotte and 1 guest