diff --git a/examples/transmit_fsk_beacon/main/main.c b/examples/transmit_fsk_beacon/main/main.c index bdee087..c32e17d 100644 --- a/examples/transmit_fsk_beacon/main/main.c +++ b/examples/transmit_fsk_beacon/main/main.c @@ -27,6 +27,14 @@ sx127x device; void app_main() { ESP_LOGI(TAG, "starting up"); + ESP_ERROR_CHECK(gpio_set_direction((gpio_num_t) RST, GPIO_MODE_INPUT_OUTPUT)); + ESP_ERROR_CHECK(gpio_set_level((gpio_num_t) RST, 0)); + vTaskDelay(pdMS_TO_TICKS(5)); + ESP_ERROR_CHECK(gpio_set_level((gpio_num_t) RST, 1)); + vTaskDelay(pdMS_TO_TICKS(10)); + ESP_LOGI(TAG, "sx127x was reset"); + ESP_ERROR_CHECK(gpio_reset_pin((gpio_num_t) RST)); + spi_bus_config_t config = { .mosi_io_num = MOSI, .miso_io_num = MISO, diff --git a/src/sx127x.c b/src/sx127x.c index a1b6fce..f970395 100644 --- a/src/sx127x.c +++ b/src/sx127x.c @@ -980,10 +980,7 @@ int sx127x_fsk_ook_tx_start_beacon(const uint8_t *data, uint8_t data_length, uin float timer2_resolution = 0.0f; uint8_t timer2_coefficient = 0; - if (interval_ms <= 255 * p1) { - timer1_resolution = p1; - timer1_coefficient = (uint8_t) (interval_ms / p1); - } else if (interval_ms <= 255 * p1 * 2) { + if (interval_ms <= 255 * p1 * 2) { timer1_resolution = p1; timer2_resolution = p1; timer1_coefficient = (uint8_t) (interval_ms / p1 / 2); @@ -1008,10 +1005,7 @@ int sx127x_fsk_ook_tx_start_beacon(const uint8_t *data, uint8_t data_length, uin timer2_resolution = p3; timer1_coefficient = (uint8_t) (interval_ms / p3 / 2); } - - if (timer2_resolution != 0) { - timer2_coefficient = (uint8_t) ((interval_ms - timer1_resolution * timer1_coefficient) / timer2_resolution); - } + timer2_coefficient = (uint8_t) ((interval_ms - timer1_resolution * timer1_coefficient) / timer2_resolution); uint8_t timer_resolution = 0b00000000; if (timer1_resolution == p1) { diff --git a/test/test_sx127x.c b/test/test_sx127x.c index ca95f83..2fd9e85 100644 --- a/test/test_sx127x.c +++ b/test/test_sx127x.c @@ -169,9 +169,9 @@ void test_fsk_ook_beacon() { // test different timer settings TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fsk_ook_tx_start_beacon(data, sizeof(data), 15, device)); - TEST_ASSERT_EQUAL_INT(234, registers[0x39]); - TEST_ASSERT_EQUAL_INT(0, registers[0x3a]); - TEST_ASSERT_EQUAL_INT(0b00000111, registers[0x38]); + TEST_ASSERT_EQUAL_INT(117, registers[0x39]); + TEST_ASSERT_EQUAL_INT(117, registers[0x3a]); + TEST_ASSERT_EQUAL_INT(0b00000101, registers[0x38]); TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fsk_ook_tx_start_beacon(data, sizeof(data), 20, device)); TEST_ASSERT_EQUAL_INT(156, registers[0x39]); TEST_ASSERT_EQUAL_INT(156, registers[0x3a]);