0

我已经用 Lolin 板测试了我的RF96W LoRa板,它工作正常,但是当我开始将这些 Lora 板与基于 stm32f030r8t6 的控制器连接时,我无法接收任何数据。虽然我试图根据 Lolin 板保持 SPI 配置。电路板接线与 SPI 要求相同。

洛林工作代码:

#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 控制器不工作代码:

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

对于 Lolin 板也来自 GitHub。对于 ST,我使用来自 GitHub 的RFM95库。

4

0 回答 0