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.


Return to “STM32F4 Boards”

Who is online

Users browsing this forum: No registered users and 1 guest