Skip to content

Commit

Permalink
add rfm rx test
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Jan 13, 2024
1 parent df0127f commit 253662e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
33 changes: 33 additions & 0 deletions test/rf_rx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.27)

# Pull in SDK (must be before project)
include(../../lib/pico-sdk/pico_sdk_init.cmake)

project(rf_rx C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK
pico_sdk_init()

add_compile_options(
-Wall
-Wno-format
-Wno-unused-function
)

add_executable(rf_rx
rf_rx.cpp
)

add_subdirectory("../../lib/RadioLib" "${CMAKE_CURRENT_BINARY_DIR}/RadioLib")

# Pull in common dependencies
target_link_libraries(rf_rx pico_stdlib hardware_spi hardware_gpio hardware_timer RadioLib)


pico_enable_stdio_usb(rf_rx 1)
pico_enable_stdio_uart(rf_rx 0)

# Create map/bin/hex file etc.
pico_add_extra_outputs(rf_rx)
86 changes: 86 additions & 0 deletions test/rf_rx/rf_rx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <RadioLib.h>
#include "pico/stdlib.h"
#include "tusb.h"
#include "../../src/rfm/pico_hal.h"
#include "../../src/pins.hpp"
#include <string>

PicoHal* hal = new PicoHal(SPI_PORT, SPI_MISO, SPI_MOSI, SPI_SCK, 8000000);

SX1276 radio = new Module(hal, RFM_CS, RFM_DIO0, RADIOLIB_NC, RFM_DIO1);

int main() {
stdio_init_all();

while (!tud_cdc_connected()) {
sleep_ms(500);
}

gpio_init(RFM_CS);
gpio_set_dir(RFM_CS, GPIO_OUT);

gpio_init(RFM_RST);
gpio_set_dir(RFM_RST, GPIO_OUT);

sleep_ms(10);
gpio_put(RFM_RST, 0);
sleep_ms(10);
gpio_put(RFM_RST, 1);

printf("[SX1276] Initializing ... ");

int state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
printf("failed, code %d\n", state);
return 1;
}
printf("success!\n");

uint8_t str[8];

while (true) {
// send a packet
printf("[SX1276] Waiting for incoming transmission ... ");

int state = radio.receive(str, 4);

if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
printf("success!");

// print the data of the packet
printf("[SX1276] Data: %s\n", str);

// // print the RSSI (Received Signal Strength Indicator)
// // of the last received packet
// Serial.print(F("[SX1278] RSSI:\t\t\t"));
// Serial.print(radio.getRSSI());
// Serial.println(F(" dBm"));

// // print the SNR (Signal-to-Noise Ratio)
// // of the last received packet
// Serial.print(F("[SX1278] SNR:\t\t\t"));
// Serial.print(radio.getSNR());
// Serial.println(F(" dB"));

// // print frequency error
// // of the last received packet
// Serial.print(F("[SX1278] Frequency error:\t"));
// Serial.print(radio.getFrequencyError());
// Serial.println(F(" Hz"));

} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
printf("timeout!\n");
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
printf("CRC error!\n");
} else {
// some other error occurred
printf("failed, code %d\n", state);
}

}
return 0;

}
2 changes: 1 addition & 1 deletion test/rf_tx/rf_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main() {
// send a packet
printf("[SX1276] Transmitting packet ... ");

state = radio.transmit("Hello World!");
state = radio.transmit("test");

if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Expand Down

0 comments on commit 253662e

Please sign in to comment.