[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

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

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

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

acronis
Posts: 142
Joined: Thu Mar 02, 2017 12:32 pm

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

Post by acronis » Thu Jul 27, 2017 8:17 am

Hello

How to assign this library to SPI3 ?
A special socket for the nRF24L01 on the Board STM32F407VET6 BLACK

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

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

Post by stevestrong » Thu Jul 27, 2017 8:27 am

acronis wrote:
Thu Jul 27, 2017 8:17 am
How to assign this library to SPI3 ?

Code: Select all

SPIClass mSPI(3);

acronis
Posts: 142
Joined: Thu Mar 02, 2017 12:32 pm

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

Post by acronis » Thu Jul 27, 2017 8:32 am

Thank you !

Please tell me how to fix the following example for SPI3 STM32F407VET6 to work on SPI3

Code: Select all

/*

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


I do not understand this

// configure nrf24l01 radio on SPI-1 bus (MOSI-PA7, MISO PA6, signal sclk-PA5) ... the interrupt is not being used?
RF24 radio(PB0,pb1 not);


on Board reserved
// #define NRF24_CLK_PIN BOARD_SPI3_SCK_PIN // PB3
// #define NRF24_DO_PIN BOARD_SPI3_MISO_PIN // PB4
// #define NRF24_DI_PIN BOARD_SPI3_MOSI_PIN // PB5
// #define NRF24_CE_PIN PB6
// #define NRF24_CS_PIN PB7
// #define NRF24_IRQ_PIN PB8

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

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

Post by stevestrong » Thu Jul 27, 2017 8:48 am

If you refer to this package, there is a lot of work to do to clean it up...

acronis
Posts: 142
Joined: Thu Mar 02, 2017 12:32 pm

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

Post by acronis » Thu Jul 27, 2017 9:02 am

What means this string ?

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 ?

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

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

Post by stevestrong » Thu Jul 27, 2017 9:50 am

acronis wrote:
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

acronis
Posts: 142
Joined: Thu Mar 02, 2017 12:32 pm

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

Post by acronis » Sat Jul 29, 2017 1:47 pm

viewtopic.php?f=39&t=1526&start=20#p20500
RF24 radio(PB6, PB7 );


This library works on STM32F407VET6.
Thank you all.
the question is closed

User avatar
RogerClark
Posts: 7147
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Post by RogerClark » Sat Jul 29, 2017 10:03 pm

Please update you initially post and add SOLVED to the title and preferably put the solution into the beginning of the first post

Post Reply