From aeada8ac42252c76cca250008a980bf4bab7b48f Mon Sep 17 00:00:00 2001 From: Jens Steinhauser Date: Tue, 8 Jul 2014 18:16:16 +0200 Subject: Add some nRF24L01(+) captures. --- spi/nrf24l01/README | 109 ++++++++++++++ spi/nrf24l01/gen-testfiles.py | 189 +++++++++++++++++++++++++ spi/nrf24l01/nrf24l01-communication-rx.sr | Bin 0 -> 3923 bytes spi/nrf24l01/nrf24l01-communication-tx.sr | Bin 0 -> 4102 bytes spi/nrf24l01/nrf24l01-communication.sr | Bin 0 -> 7900 bytes spi/nrf24l01/nrf24l01-test-activate.sr | Bin 0 -> 454 bytes spi/nrf24l01/nrf24l01-test-excess-bytes.sr | Bin 0 -> 547 bytes spi/nrf24l01/nrf24l01-test-misc.sr | Bin 0 -> 508 bytes spi/nrf24l01/nrf24l01-test-missing-bytes.sr | Bin 0 -> 449 bytes spi/nrf24l01/nrf24l01-test-no-command.sr | Bin 0 -> 443 bytes spi/nrf24l01/nrf24l01-test-unknown-command.sr | Bin 0 -> 452 bytes spi/nrf24l01/nrf24l01-test-unknown-register.sr | Bin 0 -> 444 bytes 12 files changed, 298 insertions(+) create mode 100644 spi/nrf24l01/README create mode 100755 spi/nrf24l01/gen-testfiles.py create mode 100644 spi/nrf24l01/nrf24l01-communication-rx.sr create mode 100644 spi/nrf24l01/nrf24l01-communication-tx.sr create mode 100644 spi/nrf24l01/nrf24l01-communication.sr create mode 100644 spi/nrf24l01/nrf24l01-test-activate.sr create mode 100644 spi/nrf24l01/nrf24l01-test-excess-bytes.sr create mode 100644 spi/nrf24l01/nrf24l01-test-misc.sr create mode 100644 spi/nrf24l01/nrf24l01-test-missing-bytes.sr create mode 100644 spi/nrf24l01/nrf24l01-test-no-command.sr create mode 100644 spi/nrf24l01/nrf24l01-test-unknown-command.sr create mode 100644 spi/nrf24l01/nrf24l01-test-unknown-register.sr (limited to 'spi') diff --git a/spi/nrf24l01/README b/spi/nrf24l01/README new file mode 100644 index 0000000..0d7667c --- /dev/null +++ b/spi/nrf24l01/README @@ -0,0 +1,109 @@ +------------------------------------------------------------------------------- +nRF24L01/nRF24L01+ +------------------------------------------------------------------------------- + +This directory contains a capture of the communication between two nRF24L01+ +tranceivers, one connected to a Raspberry Pi and the other connected to an +AVR microcontroller, and some generated files to test paths in the protocol +decoder that aren't covered in the capture. + + +nrf24l01-communication.sr +------------------------- + +Logic analyzer setup +-------------------- + +The logic analyzer used was a Lcsoft Mini Board (at 12MHz): + + Probe Description + --------------------------- + PB0 (TRG) used to trigger the logic analyzer + PB1 (rpi_CSN) chip select signal of the receiving chip, active low + PB2 (rpi_CLK) clock signal of the receiving chip + PB3 (rpi_MOSI) MOSI signal of the receiving chip + PB4 (rpi_MISO) MISO signal of the receiving chip + PB5 (rpi_IRQ) interrupt signal fo the receiving chip, active low + PD0 (uc_CSN) chip select signal of the sending chip, active low + PD1 (uc_CLK) clock signal of the sending chip + PD2 (uc_MOSI) MOSI signal of the sending chip + PD3 (uc_MISO) MISO signal of the sending chip + + Note that the nRF24L01(+) chips have two chip select pins, "CE" used to + control the standby mode, and "CSN" used for SPI communication. This capture + only contains the "CSN" signals of the two chips. + +Data +---- + +The sigrok command line used was: + + sigrok-cli --driver fx2lafw --config samplerate=12M \ + -p '0=TRG,1=rpi_CSN,2=rpi_CLK,3=rpi_MOSI,4=rpi_MISO,5=rpi_IRQ,8=uc_CSN,9=uc_CLK,10=uc_MOSI,11=uc_MISO' \ + -t TRG=0 --time 140 -o nrf24l01-communication.sr + +The capture starts with the Raspberry Pi initializing its chip as a receiver, +followed by the microcontroller initializing the second chip as a transmitter +at about 8.8ms - 9ms. 30ms after the start of the capture, the microcontroller +starts sending the strings "message #0" to "message #9" in intervalls of about +10ms. After sending a message, it uses polling to detect when the message is +sent and the acknowledge from the receiver is received. The Raspberry Pi handles +the first six messages after the receiving chip asserts the interrupt signal. +Because it doesn't handle the other four messages and the receive fifo in the +receiver runs full after three messages, the last message isn't acknowledged. +The sender detects that and reads the lost packet counter from the sender chip, +which consequently has a value of one. + + +nrf24l01-communication-[rx|tx].sr +---------------------------- + +These files were generated from the file 'nrf24l01-communication.sr' using +the commands + + sigrok-cli -i nrf24l01-communication.sr -O csv | \ + awk -F , '{if (NR > 3) {print $2","$3","$4","$5}}' | \ + sigrok-cli -i /dev/fd/0 -I csv:samplerate=12M -o nrf24l01-communication-rx.sr + +and + + sigrok-cli -i nrf24l01-communication.sr -O csv | \ + awk -F , '{if (NR > 3) {print $7","$8","$9","$10}}' | \ + sigrok-cli -i /dev/fd/0 -I csv:samplerate=12M -o nrf24l01-communication-tx.sr + +respectively, because apparently the pdtest/runtc tools don't support capture +files with extra channels. The files are then used to check if the protocol +decoder correctly decodes the message payload. + + +nrf24l01-test-... +-------------------- + +These files were generated by the 'gen-testfiles.py' script and contain test +cases for the decoder that aren't yet covered by the other captures. + + ...-activate.sr: Tests decoding of the 'ACTIVATE' instruction. This + instruction is only valid for the nRF24L01 chips + (without the plus) and is therefore not in the + communication dump. + + ...-excess-bytes.sr: Used to check if the protocol decoder correctly + recognizes and reports superfluous bytes after the + commands. + + ...-misc.sr: Contains checks for the instructions 'REUSE_TX_PL', + 'R_RX_PL_WID', and 'W_ACK_PAYLOAD', that aren't + covered by the other dumps. + + ...-missing-bytes.sr: Used to check if the protocol decoder correctly + recognizes and reports missing bytes after the + commands. + + ...-no-command.sr: Used to check if the protocol decoder correctly + handles empty commands. + + ...-unknown-command.sr: Used to check if the protocol decoder correctly + recognizes commands that do not exist. + + ...-unknown-register.sr: Contains a 'R_REGISTER' (read register) instruction + of a non-existing register. diff --git a/spi/nrf24l01/gen-testfiles.py b/spi/nrf24l01/gen-testfiles.py new file mode 100755 index 0000000..5b14e43 --- /dev/null +++ b/spi/nrf24l01/gen-testfiles.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python3 +## +## This file is part of the sigrok-dumps project. +## +## Copyright (C) 2014 Jens Steinhauser +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + +## This script generates test cases for the nrf24l01 protocol decoder. + +import csv +import subprocess +import tempfile + +class SPI: + def __init__(self, filename): + self._filename = filename + self._data = [] + + def CSlow(self): + self._data.append([1, 0, 0, 0]) + self._data.append([0, 0, 0, 0]) + + def CShigh(self): + self._data.append([0, 0, 0, 0]) + self._data.append([1, 0, 0, 0]) + + def add(self, mosi, miso): + for _ in range(8): + mo = mosi & 0x80 + mi = miso & 0x80 + mosi <<= 1 + miso <<= 1 + self._data.append([0, 0, mo, mi]) + self._data.append([0, 1, mo, mi]) + + self._data.append([0, 0, 0, 0]) + + def write(self): + with tempfile.NamedTemporaryFile() as tf: + with open(tf.name, 'w') as tff: + w = csv.writer(tff) + w.writerow(['CS', 'CLK', 'MOSI', 'MISO']) + w.writerows(self._data) + + fn = '{}.sr'.format(self._filename) + I = 'csv:header=true:samplerate=1k' + subprocess.check_call(['sigrok-cli', '-I', I, '-i', tf.name, '-o', fn]) + +spi = SPI('nrf24l01-test-activate') +spi.CSlow() +spi.add(0x50, 0x00) # ACTIVATE +spi.add(0x73, 0x00) # correct payload +spi.CShigh() +spi.CSlow() +spi.add(0x50, 0x00) # ACTIVATE +spi.add(0x74, 0x00) # wrong payload +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-excess-bytes') +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.CShigh() +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) # excess +spi.CShigh() +spi.CSlow() +spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) # excess +spi.CShigh() +spi.CSlow() +spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) # excess +spi.add(0x00, 0x00) # excess +spi.CShigh() +spi.CSlow() +spi.add(0x2a, 0x00) # W_REGISTER, reg = RX_ADDR_P0 +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) # excess +spi.CShigh() +spi.CSlow() +spi.add(0x2c, 0x00) # W_REGISTER, reg = RX_ADDR_P2 +spi.add(0x00, 0x00) +spi.add(0x00, 0x00) # excess +spi.CShigh() +spi.CSlow() +spi.add(0xa0, 0x00) # W_ACK_PAYLOAD, pipe = 0 +for i in range(33): + spi.add(i, 0x00) # write 33 bytes, command only expects 32 +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-missing-bytes') +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.CShigh() +spi.CSlow() +spi.add(0xb0, 0x00) # W_TX_PAYLOAD_NOACK +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-no-command') +spi.CSlow() +spi.CShigh() +spi.CSlow() +spi.CShigh() +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.CShigh() +spi.CSlow() +spi.CShigh() +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-unknown-register') +spi.CSlow() +spi.add(0x1f, 0x00) # R_REGISTER, reg = 0x1f +spi.add(0x00, 0x00) +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-unknown-command') +spi.CSlow() +spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.CShigh() +spi.CSlow() +spi.add(0xf0, 0x00) # wrong command +spi.add(0x00, 0x00) +spi.CShigh() +spi.CSlow() +spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG +spi.add(0x00, 0x00) +spi.CShigh() +spi.write() + +spi = SPI('nrf24l01-test-misc') +spi.CSlow() +spi.add(0xe3, 0x00) # REUSE_TX_PL +spi.CShigh() +spi.CSlow() +spi.add(0x60, 0x00) # R_RX_PL_WID +spi.add(0x00, 0x09) +spi.CShigh() +spi.CSlow() +spi.add(0x60, 0x00) # R_RX_PL_WID +spi.CShigh() +spi.CSlow() +spi.add(0x60, 0x00) # R_RX_PL_WID +spi.add(0x00, 0x09) +spi.add(0x00, 0x09) # excess +spi.CShigh() +spi.CSlow() +spi.add(0xa9, 0x00) # W_ACK_PAYLOAD, pipe = 1 +for i in range(5): + spi.add(i, 0x00) +for c in 'abcdef': + spi.add(ord(c), 0x00) +for i in range(5): + spi.add(i, 0x00) +spi.CShigh() +spi.write() diff --git a/spi/nrf24l01/nrf24l01-communication-rx.sr b/spi/nrf24l01/nrf24l01-communication-rx.sr new file mode 100644 index 0000000..bc25f6b Binary files /dev/null and b/spi/nrf24l01/nrf24l01-communication-rx.sr differ diff --git a/spi/nrf24l01/nrf24l01-communication-tx.sr b/spi/nrf24l01/nrf24l01-communication-tx.sr new file mode 100644 index 0000000..0dbf2e3 Binary files /dev/null and b/spi/nrf24l01/nrf24l01-communication-tx.sr differ diff --git a/spi/nrf24l01/nrf24l01-communication.sr b/spi/nrf24l01/nrf24l01-communication.sr new file mode 100644 index 0000000..faa3d6b Binary files /dev/null and b/spi/nrf24l01/nrf24l01-communication.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-activate.sr b/spi/nrf24l01/nrf24l01-test-activate.sr new file mode 100644 index 0000000..fddb811 Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-activate.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-excess-bytes.sr b/spi/nrf24l01/nrf24l01-test-excess-bytes.sr new file mode 100644 index 0000000..7b64fd2 Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-excess-bytes.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-misc.sr b/spi/nrf24l01/nrf24l01-test-misc.sr new file mode 100644 index 0000000..247691f Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-misc.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-missing-bytes.sr b/spi/nrf24l01/nrf24l01-test-missing-bytes.sr new file mode 100644 index 0000000..c1b15db Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-missing-bytes.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-no-command.sr b/spi/nrf24l01/nrf24l01-test-no-command.sr new file mode 100644 index 0000000..4b0e0dd Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-no-command.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-unknown-command.sr b/spi/nrf24l01/nrf24l01-test-unknown-command.sr new file mode 100644 index 0000000..6c72667 Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-unknown-command.sr differ diff --git a/spi/nrf24l01/nrf24l01-test-unknown-register.sr b/spi/nrf24l01/nrf24l01-test-unknown-register.sr new file mode 100644 index 0000000..633abc6 Binary files /dev/null and b/spi/nrf24l01/nrf24l01-test-unknown-register.sr differ -- cgit v1.2.3-54-g00ecf