diff --git a/afsk/ax5043.c b/afsk/ax5043.c index f74b4ad9..8ed001f5 100644 --- a/afsk/ax5043.c +++ b/afsk/ax5043.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "ax25.h" #include "ax5043.h" #include "status.h" @@ -447,11 +448,10 @@ int ax5043_set_tx_freq(ax5043_conf_t *conf, uint32_t freq) { conf->tx_freq = freq; /* If the frequency difference is great enough perform autoranging */ -/* if (freq + 25000000 > prev_freq || freq - 25000000 < prev_freq) { ax5043_autoranging(conf); } -*/ + return PQWS_SUCCESS; } @@ -616,23 +616,33 @@ int ax5043_autoranging(ax5043_conf_t *conf) { val = BIT(4) | AX5043_VCOR_INIT; ret = ax5043_spi_write_8(conf, pllranging_reg, val); if (ret) { + printf("ERROR: AX5043 Autoranging Write Failure\n\n"); return ret; } usleep(10); - val = 0; + //val = 0; /* Wait until the autoranging is complete */ - while ((val & BIT(4)) == 0) { + int timeout = 0; + clock_t start = clock(); + while (((val & BIT(4)) != 0) && !timeout ) { // changed to !=, since https://www.onsemi.com/pub/Collateral/AND9347-D.PDF says BIT(4) RNG START clears when autoranging done ret = ax5043_spi_read_8(conf, &val, pllranging_reg); if (ret) { + printf("ERROR: AX5043 Autoranging Read Failure\n\n"); return ret; } + if ((clock() - start) > 1000000) { + timeout = 1; + } } if (val & BIT(5)) { + printf("ERROR: AX5043 Autoranging Error\n\n"); return -PQWS_AX5043_AUTORANGING_ERROR; + } else if (timeout) { + printf("ERROR: AX5043 Autoranging Timeout\n\n"); + return -1; } - return PQWS_SUCCESS; }