[SOLVED] STM32F4 +RF24 library problem
41300895 Sun Nov 06, 2016 11:31 am
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)41300895 Sun Nov 06, 2016 11:31 am
RF24 radio(PA3,PA4)Ollie Sun Nov 06, 2016 4:35 pm
Cheers, Ollie
41300895 Sun Nov 06, 2016 5:32 pm
zmemw16 Mon Nov 07, 2016 10:58 am
also this line intrigues me
#include <../../libraries/RF24/RF24.h>
41300895 Mon Nov 07, 2016 1:14 pm
#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
stevestrong Mon Nov 07, 2016 5:03 pm
41300895 Mon Nov 07, 2016 5:39 pm
#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
stevestrong Sat Nov 12, 2016 8:19 am
zmemw16 Sat Nov 12, 2016 12:43 pm
zmemw16 Sun Nov 13, 2016 7:37 am
41300895 Sun Nov 13, 2016 9:44 am
zmemw16 Sun Nov 13, 2016 8:52 pm
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
zmemw16 Mon Nov 14, 2016 3:10 pm
stephen
Manny Mon Nov 14, 2016 6:03 pm
41300895 Wed Nov 23, 2016 5:44 am
41300895 Wed Nov 23, 2016 3:42 pm
#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
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
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