From c4a9d02bd51a5cbc515190d23a084ea81816df40 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 15 Dec 2020 08:23:11 +0100 Subject: [PATCH] Trigger working --- nanovna.h | 2 +- sa_core.c | 17 ++++++++++------- si4432.c | 31 ++++++++++++++++++++----------- si4432.h | 1 + 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/nanovna.h b/nanovna.h index 3def0ad..913bdb2 100644 --- a/nanovna.h +++ b/nanovna.h @@ -376,7 +376,7 @@ extern uint16_t graph_bottom; // Maximum menu buttons count #define MENU_BUTTON_MAX 8 #define MENU_BUTTON_WIDTH 80 -#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/8-2) +#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/8-1) #define MENU_BUTTON_BORDER 1 #define KEYBOARD_BUTTON_BORDER 2 #define FORM_BUTTON_BORDER 2 diff --git a/sa_core.c b/sa_core.c index 53cf5d2..c8c041c 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1755,6 +1755,9 @@ static void calculate_static_correction(void) // Calculate the correct_RSSI = #ifdef __SI4432__ getSI4432_RSSI_correction() +#endif +#ifdef __SI4463__ + getSI4463_RSSI_correction() #endif - get_signal_path_loss() + float_TO_PURE_RSSI( @@ -2195,11 +2198,10 @@ modulation_again: pureRSSI = DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI)); #endif #ifdef __SI4463__ - pureRSSI = DEVICE_TO_PURE_RSSI((deviceRSSI_t)Si446x_RSSI()); + pureRSSI = Si446x_RSSI(); #endif if (break_on_operation && operation_requested) // allow aborting a wait for trigger return 0; // abort - // Store data level bitfield (remember only last 2 states) // T_LEVEL_UNDEF mode bit drop after 2 shifts data_level = ((data_level<<1) | (pureRSSI < trigger_lvl ? T_LEVEL_BELOW : T_LEVEL_ABOVE))&(T_LEVEL_CLEAN); @@ -2214,8 +2216,8 @@ modulation_again: SI4432_Fill(MODE_SELECT(setting.mode), 1); // fast mode possible to pre-fill RSSI buffer } #endif -#ifdef __SI446x__ - if (setting.spur_removal == 0 && SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { +#ifdef __SI4463__ + if (/* S_STATE(setting.spur_removal) == 0 && */ SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { SI446x_Fill(MODE_SELECT(setting.mode), 1); // fast mode possible to pre-fill RSSI buffer } #endif @@ -2225,7 +2227,8 @@ modulation_again: } start_of_sweep_timestamp = chVTGetSystemTimeX(); } - else { + else + { #ifdef __SI4432__ pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer #endif @@ -2234,8 +2237,8 @@ modulation_again: #endif } #ifdef __SPUR__ - static pureRSSI_t spur_RSSI = -1; // Initialization only to avoid warning. - if (S_STATE(setting.spur_removal)) { + static pureRSSI_t spur_RSSI = 10000; // Initialization only to avoid warning. + if (setting.mode == M_LOW && S_STATE(setting.spur_removal)) { if (!spur_second_pass) { // If first spur pass spur_RSSI = pureRSSI; // remember measure RSSI spur_second_pass = true; diff --git a/si4432.c b/si4432.c index 4ce4a9d..2f4669f 100644 --- a/si4432.c +++ b/si4432.c @@ -43,8 +43,8 @@ // Hardware or software SPI use #ifdef USE_HARDWARE_SPI_MODE #define SI4432_SPI SPI1 -#define SI4432_SPI_SPEED SPI_BR_DIV8 //#define SI4432_SPI_SPEED SPI_BR_DIV64 +#define SI4432_SPI_SPEED SPI_BR_DIV8 static uint32_t old_spi_settings; #else static uint32_t old_port_moder; @@ -1236,7 +1236,7 @@ int SI4463_wait_for_cts(void) { set_SPI_mode(SPI_MODE_SI); while (!SI4463_READ_CTS) { - my_microsecond_delay(10); + my_microsecond_delay(1); } return 1; } @@ -1266,7 +1266,6 @@ void SI4463_write_buffer(uint8_t ADR, uint8_t *DATA, int len) uint8_t SI4463_read_byte( uint8_t ADR ) { - set_SPI_mode(SPI_MODE_SI); uint8_t DATA ; set_SPI_mode(SPI_MODE_SI); SI_CS_LOW; @@ -1303,7 +1302,7 @@ uint8_t SI4463_wait_response(void* buff, uint8_t len, uint8_t use_timeout) uint16_t timeout = 40000; while(!SI4463_get_response(buff, len)) { - my_microsecond_delay(10); + my_microsecond_delay(1); if(use_timeout && !--timeout) { ((char *)buff)[0] = 1; @@ -1322,10 +1321,13 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) if (SI4463_wait_for_cts()) #endif { +// SPI_BR_SET(SI4432_SPI, SPI_BR_DIV8); + SI_CS_LOW; for(uint8_t i=0;i= sweep_points) break; if (t) @@ -1770,22 +1775,22 @@ int16_t Si446x_RSSI(void) SI4463_frequency_changed = false; } - int j = 3; //setting.repeat; + int j = 1; //setting.repeat; int RSSI_RAW_ARRAY[3]; do{ again: data[0] = SI446X_CMD_GET_MODEM_STATUS; data[1] = 0xFF; - SI4463_do_api(data, 2, data, 3); + SI4463_do_api(data, 2, data, 3); // TODO no clear of interrupts if (data[2] == 255) { my_microsecond_delay(10); goto again; } - RSSI_RAW_ARRAY[--j] = data[2] - 120 * 2; + RSSI_RAW_ARRAY[--j] = data[2]; if (j == 0) break; - my_microsecond_delay(100); + my_microsecond_delay(20); }while(1); -#if 1 +#if 0 int t; if (RSSI_RAW_ARRAY[0] > RSSI_RAW_ARRAY[1]) { t = RSSI_RAW_ARRAY[1]; @@ -2128,6 +2133,10 @@ const int SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); static pureRSSI_t SI4463_RSSI_correction = float_TO_PURE_RSSI(-120); static int prev_band = -1; +pureRSSI_t getSI4463_RSSI_correction(void){ + return SI4463_RSSI_correction; +}; + uint16_t force_rbw(int f) { @@ -2210,7 +2219,7 @@ void SI4463_set_freq(uint32_t freq) my_microsecond_delay(10); } if ((SI4463_band == prev_band)) { - int vco = 2091 + (((freq - 850000000)/1000) * 492) / 200000; + int vco = 2091 + ((((freq / 4 ) * SI4463_outdiv - 850000000)/1000) * 492) / 200000; if (SI4463_in_tx_mode) { uint8_t data[] = { diff --git a/si4432.h b/si4432.h index 38b48ac..ad541f0 100644 --- a/si4432.h +++ b/si4432.h @@ -188,6 +188,7 @@ si446x_state_t getState(void); void setState(si446x_state_t newState); extern const int SI4432_RBW_count; extern si446x_info_t SI4463_info; +pureRSSI_t getSI4463_RSSI_correction(void); void Si446x_getInfo(si446x_info_t* info); void SI446x_Fill(int s, int start); void SI4463_init(void);