So I'm working on a remote RC car project. I'm using an Arduino Mega as the "main" controller. It's used to control the motors, LEDs and read the ultrasonic sensors to make sure that the car doesn't bump into something. The remote controller uses an STM32F103C microcontroller because I wanted to have a fast MCU for the remote to reduce latency so that the car responds to the remote controller ASAP. The car and the remote communicate using a NRF24+ module. I found an NRF24 library for the STM32 (GitHub - jaretburkett/RF24-STM: RF24 for STM32duino. nRF24L01+ supporf for STM32F103 Arduino). On my Arduino Mega, I'm using TMRh20's NRF24 library.
The issue is that the transmitter is transmitting successfully, but the receiver isn't receiving anything. On my Arduino Mega, I also tried to check if the isChipConnected function returns true, and it does. I also tried this connection tester sketch:
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
const int pinCE = 7;
const int pinCSN = 8;
RF24 wirelessSPI(pinCE, pinCSN);
const uint64_t pAddress = 0xB00B1E5000LL;
void setup(){
Serial.begin(115200);
printf_begin();
wirelessSPI.begin();
wirelessSPI.setDataRate(RF24_2MBPS);
wirelessSPI.openWritingPipe(pAddress);
wirelessSPI.stopListening();
wirelessSPI.printDetails();
}
void loop(){
}
And it shows correct info. I also tried this sketch on my STM32 (I just changed the library so it uses the modified one - github link above), and it prints the same correct info. I also tried using TMRh20's library on the STM32, but the printDetains() function doesn't work, but I tried the isChipConnected function and it returns true and transmission also seems to work, but the Arduino Mega is not receiving anything.
I also tried to swap the two sketches, so the STM32 was the receiver and the Arduino Mega was the transmitter, but nothing changed. The isChipConnected function was returning true on both and the transmitter was "transmitting successfully", but the receiver wasn't getting anything.
Here's my transmitter sketch:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
const int pinCE = 7;
const int pinCSN = 8;
RF24 wirelessSPI(pinCE, pinCSN);
const uint64_t pAddress = 0x68;
void setup(){
Serial.begin(115200);
printf_begin();
wirelessSPI.begin();
wirelessSPI.setPALevel(RF24_PA_LOW);
wirelessSPI.setDataRate(RF24_2MBPS);
wirelessSPI.openWritingPipe(pAddress);
wirelessSPI.stopListening();
wirelessSPI.printDetails();
}
void loop(){
if(!wirelessSPI.isChipConnected()){
Serial.println("Error");
return;
}
String text = "Ping!";
char dataToSend[24];
text.toCharArray(dataToSend, sizeof(dataToSend));
wirelessSPI.write(&dataToSend, sizeof(dataToSend));
Serial.print("Transmitted: ");
Serial.println(dataToSend);
delay(500);
}
And my receiver code:
#include <SPI.h>
#include "nRF24L01-STM.h"
#include "RF24-STM.h"
const int pinCE = PB1;
const int pinCSN = PA4;
RF24 wirelessSPI(pinCE, pinCSN);
const uint64_t pAddress = 0x68;
void setup(){
Serial.begin(115200);
wirelessSPI.begin();
wirelessSPI.setPALevel(RF24_PA_LOW);
wirelessSPI.setDataRate(RF24_2MBPS);
wirelessSPI.openReadingPipe(1, pAddress);
wirelessSPI.startListening();
}
void loop(){
if(!wirelessSPI.isChipConnected()){
Serial.println("Error");
return;
}
if(wirelessSPI.available()){
char data[24] = "";
wirelessSPI.read(&data, sizeof(data));
Serial.println("Received: " + String(data));
}
}