Browse Source

recommend to check wiring & bus selection when receiving chip version 0

Fabian Peter Hammerle 3 years ago
parent
commit
ed0dfb0b1e
3 changed files with 32 additions and 6 deletions
  1. 2 0
      CHANGELOG.md
  2. 10 5
      cc1101/__init__.py
  3. 20 1
      tests/test_spi.py

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Fixed
+- recommend to check wiring & bus selection when receiving chip version `0`
 
 ## [2.7.1] - 2021-02-08
 ### Fixed

+ 10 - 5
cc1101/__init__.py

@@ -513,12 +513,17 @@ class CC1101:
             )
         version = self._read_status_register(StatusRegisterAddress.VERSION)
         if version not in self._SUPPORTED_VERSIONS:
-            raise ValueError(
-                "unsupported chip version 0x{:02x} (expected one of [{}])".format(
-                    version,
-                    ", ".join("0x{:02x}".format(v) for v in self._SUPPORTED_VERSIONS),
-                )
+            msg = "Unsupported chip version 0x{:02x} (expected one of [{}])".format(
+                version,
+                ", ".join("0x{:02x}".format(v) for v in self._SUPPORTED_VERSIONS),
             )
+            if version == 0:
+                msg += (
+                    "\n\nPlease verify that all required pins are connected"
+                    " (see https://github.com/fphammerle/python-cc1101#wiring-raspberry-pi)"
+                    " and that you selected the correct SPI bus and chip/slave select line."
+                )
+            raise ValueError(msg)
 
     def _configure_defaults(self) -> None:
         # next major/breaking release will probably stick closer to CC1101's defaults

+ 20 - 1
tests/test_spi.py

@@ -120,7 +120,7 @@ def test___enter___unsupported_chip_version(transceiver):
             ValueError,
             match=r"^{}$".format(
                 re.escape(
-                    "unsupported chip version 0x15 (expected one of [0x04, 0x14])"
+                    "Unsupported chip version 0x15 (expected one of [0x04, 0x14])"
                 )
             ),
         ):
@@ -128,6 +128,25 @@ def test___enter___unsupported_chip_version(transceiver):
                 pass
 
 
+def test___enter___chip_version_zero(transceiver):
+    with unittest.mock.patch.object(
+        transceiver, "_read_status_register"
+    ) as read_status_register_mock, unittest.mock.patch.object(transceiver, "_reset"):
+        read_status_register_mock.side_effect = lambda r: {
+            cc1101.addresses.StatusRegisterAddress.PARTNUM: 0x00,
+            cc1101.addresses.StatusRegisterAddress.VERSION: 0x00,
+        }[r]
+        with pytest.raises(
+            ValueError,
+            match=r"^Unsupported chip version 0x00 \(expected one of \[0x04, 0x14\]\)"
+            r"\n\nPlease verify that all required pins are connected"
+            r" \(see https://github\.com/fphammerle/python\-cc1101\#wiring\-raspberry\-pi\)"
+            r" and that you selected the correct SPI bus and chip/slave select line\.$",
+        ):
+            with transceiver:
+                pass
+
+
 @pytest.mark.parametrize("bus", [0, 1])
 @pytest.mark.parametrize("chip_select", [0, 2])
 def test___enter__permission_error(transceiver, bus, chip_select):