Hello,
Actually, relaunching the call
of libusb_control_transfer
in rtlsdr_demod_write_reg
does the trick for all three messages and sets the frequency correctly without
error message. This seems to fix also the gain not being set.
The call of rtlsdr_demod_read_reg is necessary before recalling
libusb_control_transfer, if we juste call libusb_control_transfer a 2nd time
this doesn't work.
The patch in my initial post is not necessary if this one is applied.
Pull request: https://github.com/steve-m/librtlsdr/pull/58
Regards
Le mercredi 2 octobre 2019, 08:25:54 CEST Fab Stz a écrit :
> Hello,
>
> When doing a setFrequency I usually have this error afterwards and the
> frequency is actually not changed
>
> rtlsdr_demod_write_reg failed with -9
> r82xx_write: i2c wr failed=-9 reg=17 len=1
> r82xx_set_freq: failed=-9
>
> By searching around I found this commit that makes the trick for me.
> https://github.com/keenerd/rtl-sdr/commit/
> 9ed9ffa37e24f3293fa960cfcd74909ac3e9996c
>
> This will actually really set the frequency and remove the last 2 errors
> related to "r82xx". The only error remaining is then
>
> rtlsdr_demod_write_reg failed with -9
>
>
> If you can include that upstream that would be nice.
> I created a pull request here : https://github.com/steve-m/librtlsdr/pull/56
>
> Actually the commit is part of a large PR that you may be interested in ?
> https://github.com/keenerd/rtl-sdr/pull/8
>
> Regards,
--- rtl-sdr-0.6/src/librtlsdr.c.orig 2018-08-26 14:54:51.000000000 +0200
+++ rtl-sdr-0.6/src/librtlsdr.c 2019-10-02 10:35:11.510191867 +0200
@@ -534,6 +534,7 @@
int rtlsdr_demod_write_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint16_t val, uint8_t len)
{
int r;
+ int retries = 2;
unsigned char data[2];
uint16_t index = 0x10 | page;
addr = (addr << 8) | 0x20;
@@ -545,13 +546,15 @@
data[1] = val & 0xff;
- r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
-
+ do {
+ r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
+ rtlsdr_demod_read_reg(dev, 0x0a, 0x01, 1);
+ retries--;
+ } while (retries > 0 && r < 0);
+
if (r < 0)
fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
- rtlsdr_demod_read_reg(dev, 0x0a, 0x01, 1);
-
return (r == len) ? 0 : -1;
}