Hello,
We are a group of students who carry out a supervision project.
We use a NUCLEO 64 F401RE card (STMicroelectronics) and a NUCLEO-LRWAN1 card (STMicroelectronics).
The goal is to set up communication via the LORA wireless network.
However, we have a problem with the NUCLEO-LRWAN1 card.
The program compiles correctly, but at runtime we get the following message in the serial monitor: "Lora module not ready"
We are unable to figure out how to resolve this persistent problem.
We used the sample programs first and tried modify them using other programs offered on the forum (without any success).
Thank you in advance for your help.
/*
LoRaOTAA.ino
Establish a connection on a LoRaWAN network in OTAA mode.
Send a join request and wait the join accept.
Exchange data to/from the network.
Extract of the LoRaWAN standard:
For Over The Air Activation, end-devices must follow a join procedure prior to participating in
data exchanges with the network server. An end-device has to go through a new join
procedure every time it has lost the session context information.
The join procedure requires the end-device to be personalized with the following information
before its starts the join procedure: a globally unique end-device identifier (DevEUI), the
application identifier (AppEUI), and an AES-128 key (AppKey).
USI will burn the unique IEEE EUI64 at factory.
*/
#include "LoRaWANNode.h"
#define FRAME_DELAY 300000 // in ms. Every 5 minutes by default.
// Serial port use to communicate with the USI shield.
// By default, use D0 (Rx) and D1(Tx).
// For Nucleo64, see "Known limitations" chapter in the README.md
HardwareSerial SerialLora(PA2, PA3); //(PC10, PC11); // PA2 PA3
// AppKey and AppEUI.
const char appKey[] = "78FCD341D4xxxxxxxxxxxxxxxxE3959B0";
const char appEUI[] = "70B3xxxxxxxx77C";
// Data send
char frameTx[] = "Hello world!";
void setup()
{
Serial.begin(115200);
SerialLora.begin(115200);
Serial.println("-- LoRaWAN OTAA sketch --");
// Enable the USI module and set the radio band.
while(!loraNode.begin(&SerialLora, LORA_BAND_EU_868)) {
Serial.println("Lora module not ready");
delay(1000);
}
// Send a join request and wait the join accept
while(!loraNode.joinOTAA(appKey, appEUI)) {
Serial.println("joinOTAA failed!!");
delay(1000);
}
Serial.println("Lora module ready, join accepted.\n");
String str = "Device EUI: ";
loraNode.getDevEUI(&str);
Serial.println(str);
str = "Application key: ";
loraNode.getAppKey(&str);
Serial.println(str);
str = "Application EUI: ";
loraNode.getAppEUI(&str);
Serial.println(str);
}
void loop()
{
receive();
transmit();
delay(FRAME_DELAY);
}
void receive(void) {
uint8_t frameRx[64];
uint8_t len;
uint8_t port;
// Check if data received from a gateway
if(loraNode.receiveFrame(frameRx, &len, &port)) {
uint8_t n = 0;
Serial.print("frame received: 0x");
while(len > 0) {
Serial.print(frameRx[n], HEX);
Serial.print(',');
len--;
n++;
}
Serial.print(" on port "); Serial.println(port);
} else {
Serial.println("No data");
}
}
void transmit(void) {
// Send unconfirmed data to a gateway (port 1 by default)
int status = loraNode.sendFrame(frameTx, sizeof(frameTx), UNCONFIRMED);
if(status == LORA_SEND_ERROR) {
Serial.println("Send frame failed!!!");
} else if(status == LORA_SEND_DELAYED) {
Serial.println("Module busy or duty cycle");
} else {
Serial.println("Frame sent");
}
}
For PA2 and PA3, it looks like you should use hardwareSerial2 instead of hardwareSerial .
Edit:
but also look for another pinout which shows all the pin labels for all the pins. You may need that serial port for the programmer and should look for other ones.
That's indeed an important information and it seems to be the same on the nucleo 401 board. So the TO should use another serial line or change the solder bridges.
The USART pins (= Serial) used by default are the D0 / D1 pins. These are USART2 pins (= Serial2) according to our research set by default.
So we tried to use other USART pins (but not the same as the default).
We have selected the USART1 (Serial1).
Serial1 TX pins are available on D8 (= PA_9) and D10 (= PB_6).
Serial1 RX pins are available on D2 (= PA_10) and on the Morpho connector.
So we tested with USART1 PA9 / PA10 pins.
I don't think you can simply change the serial pins without making a corresponding change to the port. Have you tried changing Y here:
HardwareSerialY SerialLora( RXpin, TXpin);
Edit
Instead of soldering and breaking jumpers, one option may be to remove the Lora shield and connect it to the Nucleo board with Dupont jumper wires. Then you'll be free to use some of the "non-Arduino" pins on that board.
Edit2
Can you find the Lora program on Github and post a link to it. I've seen where the serial baud rate is set at only 9600. You are using 115200 which may not match the board.