3

I have tested my RF96W LoRa boards with the Lolin Boards, it works fine. However when I interface these Lora boards with a stm32f030r8t6 based controller, I don't receive any data, although I have tried to keep the SPI configuration according to Lolin boards. Board Wiring is same as SPI requirements.

Lolin working Code:

#include <SPI.h>
#include <RH_RF95.h>

#define RFM95_CS 15
#define RFM95_RST 16
#define RFM95_INT 5

RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available

  rf95.setModemConfig(RH_RF95::Bw125Cr48Sf4096);
  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
  }
}

void loop()
{
  Serial.println("Sending to rf95_server");
  uint8_t data[] = "Hello World!";
  rf95.send(data, sizeof(data));
  
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000)) { 
    // Should be a reply message for us now   
    if (rf95.recv(buf, &len)) {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);    
    } else {
      Serial.println("recv failed");
    }
  } else {
    Serial.println("No reply, is rf95_server running?");
  }
//  delay(400);
}

STM32F030R8T6 Controller not working code:

#include <stdio.h>
#include <RF95.h>

uint8_t init_failed = 0;
uint8_t Tx_buff[] = "Hello World!";
uint8_t Rx_buff[RH_RF95_MAX_MESSAGE_LEN];
uint8_t rssi_value = 0;
uint16_t len = 0;

void SystemClock_Config(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_SPI1_Init();
//  RF95_setModemConfig(Bw125Cr48Sf4096);
    if(!RF95_Init()) {
        init_failed = 1;
    }
  while (1) {
//    RF95_send(Tx_buff);
//    RF95_waitPacketSent();
//    if(RF95_available_Timeout(3000)){
//        RF95_receive(Rx_buff);
//    }
      if (RF95_available()) {
          if (RF95_receive(Rx_buff)) {
              len = sizeof(Rx_buff);
          }
          if (len) {
              uint8_t data[] = "And hello back to you";
              RF95_send(data);
              RF95_waitPacketSent();
          }
      }
  }
}

For Lolin board library is also from GitHub. For ST I'm using RFM95 library from GitHub.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.