fphammerle / python-cc1101

Python Library & Command Line Tool to Transmit RF Signals via CC1101 Transceivers
https://pypi.org/project/cc1101/
GNU General Public License v3.0
72 stars 14 forks source link

chip verification fails on onion omega2+ #31

Open fphammerle opened 3 years ago

fphammerle commented 3 years ago
root@Omega-****:~# python3
Python 3.6.10 (default, Apr 09 2020, 14:46:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cc1101
>>> with cc1101.CC1101(spi_bus=0, spi_chip_select=1) as t:
...     print(t)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/cc1101/__init__.py", line 526, in __enter__
    self._verify_chip()
  File "/usr/lib/python3.6/site-packages/cc1101/__init__.py", line 484, in _verify_chip
    partnum, self._SUPPORTED_PARTNUM
ValueError: unexpected chip part number 112 (expected: 0)
>>> 
root@Omega-****:~# python3
Python 3.6.10 (default, Apr 09 2020, 14:46:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cc1101
>>> with cc1101.CC1101(spi_bus=0, spi_chip_select=1) as t:
...     print(t)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/cc1101/__init__.py", line 526, in __enter__
    self._verify_chip()
  File "/usr/lib/python3.6/site-packages/cc1101/__init__.py", line 484, in _verify_chip
    partnum, self._SUPPORTED_PARTNUM
ValueError: unexpected chip part number 32 (expected: 0)
>>>
root@Omega-****:~# grep ^Version /usr/lib/python3.6/site-packages/cc1101-2.6.1.dist-info/METADATA
Version: 2.6.1
root@Omega-****:~# opkg info python3 | grep Version
Version: 3.6.10-1
root@Omega-****:~# opkg info python3-spidev
Package: python3-spidev
Version: 4.0.1-2
Depends: libc, python3-base
Status: install user installed
Architecture: mipsel_24kc
Installed-Time: 1610908467

board: https://onion.io/store/omega2p/

wiring: https://docs.onion.io/omega2-docs/communicating-with-spi-devices.html

fphammerle commented 3 years ago

Same transceiver, now connected to raspberry pi 2B:

$ pip3 show cc1101 | grep ^Version
Version: 2.7.0
$ ~/.local/bin/cc1101-export-config >/dev/null
CC1101(marcstate=idle, base_frequency=800.00MHz, symbol_rate=115.05kBaud, modulation_format=ASK_OOK, sync_mode=TRANSMIT_16_MATCH_16_BITS, preamble_length=4B, sync_word=0xd391, packet_length≤255B, output_power=(0xc6,0))
fphammerle commented 3 years ago

Maybe max_speed_hz is too high, currently 55700 Hz: https://github.com/fphammerle/python-cc1101/blob/v2.6.1/cc1101/__init__.py#L524

https://github.com/OnionIoT/python-spidev/blob/ae67ece9d59d6d08114a9f1847c1d1c8576a46a3/README.md#settings

fphammerle commented 3 years ago

max_speed_hz = n with n <= 47100 triggers

Traceback (most recent call last):
  File "cc1101_test.py", line 2, in <module>
    with cc1101.CC1101(spi_bus=0, spi_chip_select=1) as t:
  File "/usr/lib/python3.6/site-packages/cc1101/__init__.py", line 524, in __enter__
    self._spi.max_speed_hz = 47100 # empirical
OSError: [Errno 22] Invalid argument
static int
SpiDev_set_max_speed_hz(SpiDevObject *self, PyObject *val, void *closure)
{
    // ...
    if (self->max_speed_hz != max_speed_hz) {
        if (ioctl(self->fd, SPI_IOC_WR_MAX_SPEED_HZ, &max_speed_hz) == -1) {
            PyErr_SetFromErrno(PyExc_IOError);
            return -1;
        }
        self->max_speed_hz = max_speed_hz;
    }
    return 0;
}

https://github.com/OnionIoT/python-spidev/blob/acde79b6ef485f7ff32daf391aef285af5091def/spidev_module.c#L661