-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df0127f
commit 253662e
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters