From 82fac14b87e1f6cc869418f5b5a4ddc7ce8a1fd0 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Fri, 5 Jul 2024 21:35:06 +0100 Subject: [PATCH] sync raspberrypi example with esp --- examples/receive_fsk_raspberrypi/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/receive_fsk_raspberrypi/main.c b/examples/receive_fsk_raspberrypi/main.c index cf66ce5..d52d2aa 100644 --- a/examples/receive_fsk_raspberrypi/main.c +++ b/examples/receive_fsk_raspberrypi/main.c @@ -15,8 +15,11 @@ // Correspond to SPI0 with chip select pin CE0 (GPIO8) on RaspberryPI #define SPI_DEVICE "/dev/spidev0.0" #define GPIO_DEVICE "/dev/gpiochip0" -// GPIO 27 +#define GPIO_DIO1_PIN 13 +#define GPIO_DIO2_PIN 19 +#define GPIO_DIO3_PIN 26 #define GPIO_DIO0_PIN 27 +#define GPIO_RESET_PIN 6 #define GPIO_POLL_TIMEOUT -1 #define LINUX_ERROR_CHECK(x) \ @@ -91,7 +94,7 @@ int reset_sx127x() { return EXIT_FAILURE; } struct gpiohandle_request rq; - rq.lineoffsets[0] = 6; + rq.lineoffsets[0] = GPIO_RESET_PIN; rq.lines = 1; rq.flags = GPIOHANDLE_REQUEST_OUTPUT; strcpy(rq.consumer_label, "sx127x_reset"); @@ -117,7 +120,7 @@ int setup_and_wait_for_interrupt(sx127x *device) { perror("unable to open device"); return EXIT_FAILURE; } - uint8_t gpios[] = {27, 13, 19, 26}; + uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN}; int gpios_length = sizeof(gpios); struct pollfd pfd[4]; for (int i = 0; i < gpios_length; i++) { @@ -180,14 +183,12 @@ int main() { sx127x *device = NULL; LINUX_ERROR_CHECK(sx127x_create(&spi_device_fd, &device)); LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device)); - LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device)); LINUX_ERROR_CHECK(sx127x_set_frequency(437200000, device)); - // perform calibration for the selected frequency - LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device)); + LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device)); LINUX_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device)); - LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(10000.0, device)); + LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device)); uint8_t syncWord[] = {0x12, 0xAD}; LINUX_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device)); @@ -196,7 +197,7 @@ int main() { LINUX_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, device)); LINUX_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device)); - LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_PREAMBLE, device)); + LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device)); LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));