{"id":15540273,"url":"https://github.com/rm-hull/spidev-test","last_synced_at":"2025-04-16T01:27:04.762Z","repository":{"id":17019164,"uuid":"81011302","full_name":"rm-hull/spidev-test","owner":"rm-hull","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-02T18:01:21.000Z","size":14,"stargazers_count":98,"open_issues_count":1,"forks_count":39,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-03T12:17:41.040Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rm-hull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-05T18:08:40.000Z","updated_at":"2024-08-14T03:27:48.000Z","dependencies_parsed_at":"2022-07-20T01:18:44.023Z","dependency_job_id":null,"html_url":"https://github.com/rm-hull/spidev-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fspidev-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fspidev-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fspidev-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fspidev-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rm-hull","download_url":"https://codeload.github.com/rm-hull/spidev-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249181216,"owners_count":21225867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T12:13:24.688Z","updated_at":"2025-04-16T01:27:04.748Z","avatar_url":"https://github.com/rm-hull.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spidev-test\n\nA copy of https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c\n(becasue I can never find it when I need it), with the following changes:\n\n * The default device was changed from `/dev/spidev1.1` to `/dev/spidev0.0`\n * The SPI modes were changed from `SPI_IOC_WR_MODE32` and `SPI_IOC_RD_MODE32` to\n   `SPI_IOC_WR_MODE` and `SPI_IOC_RD_MODE` respectively.\n\n## What is this for?\n\nIf you are experiencing issues with the [SPI](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus)\nbus on Raspberry Pi or other Linux-based single-board computers, this program\n(plus a single jumper or wire) will confirm whether SPI is working properly.\n\n## Building on Raspberry Pi / Orange Pi\n\nDownload the code from github and compile with:\n\n    $ git clone https://github.com/rm-hull/spidev-test\n    $ cd spidev-test\n    $ gcc spidev_test.c -o spidev_test\n\n## Enabling SPI on the Raspberry Pi\n\nBy default, the SPI kernel driver is **NOT** enabled on the Raspberry Pi Raspian image.\nYou can confirm whether it is enabled using the shell commands below::\n\n    $ lsmod | grep -i spi\n    spi_bcm2835             7424  0\n\nDepending on the hardware/kernel version, this may report **spi_bcm2807** rather\nthan **spi_bcm2835** - either should be adequate.\n\nCheck whether the devices are successfully installed in `/dev`:\n\n    $ ls -l /dev/spi*\n    crw------- 1 root root 153, 0 Jan  1  1970 /dev/spidev0.0\n    crw------- 1 root root 153, 1 Jan  1  1970 /dev/spidev0.1\n\nIf you have no `/dev/spi` files and nothing is showing using `lsmod` then this\nimplies the kernel SPI driver is not loaded. Enable the SPI as follows (steps\ntaken from https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial#spi-on-pi):\n\n  1. Run `sudo raspi-config`\n  2. Use the down arrow to select `9 Advanced Options`\n  3. Arrow down to `A6 SPI.`\n  4. Select **yes** when it asks you to enable SPI,\n  5. Also select **yes** when it asks about automatically loading the kernel module.\n  6. Use the right arrow to select the **\u003cFinish\u003e** button.\n  7. Select **yes** when it asks to reboot.\n\n![raspi-config](https://raw.githubusercontent.com/rm-hull/luma.led_matrix/master/doc/images/raspi-spi.png)\n\nAfter rebooting re-check that the `lsmod | grep -i spi` command shows whether\nSPI driver is loaded before proceeding. If you are stil experiencing problems, refer to the official\nRaspberry Pi [SPI troubleshooting guide](https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md#troubleshooting)\n\n## Testing the SPI bus\n\nOn RPi and other pin-compatible boards, connect pin 19 (BCM 10 = MOSI) to\npin 21 (BCM 9 = MISO) to form a loopback connection. See https://pinout.xyz\nfor further details.\n\nRun the compiled executable:\n\n    $ ./spidev_test -v\n    spi mode: 0x0\n    bits per word: 8\n    max speed: 500000 Hz (500 KHz)\n    TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....?..................?.\n    RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....?..................?.\n\n_(run with `sudo` if it shows an error about permissions)_\n\n## Interpretting the results\n\nWith the MOSI _(master out, slave in)_ pin connected to the MISO _(master in,\nslave out)_, the received data should be exactly the same as the transmitted data,\nas in the above example.\n\nIf received data is all zero as below:\n\n    $ ./spidev_test -v\n    spi mode: 0x0\n    bits per word: 8\n    max speed: 500000 Hz (500 KHz)\n    TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....?..................?.\n    RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | ................................\n\nThis implies the pins MOSI and MISO aren't connected.\n\n## Program options\n\nUse the `-?` flag to show all the available options:\n\n    $ ./spidev_test -?\n    usage: ./spidev_test [-DsbdlHOLC3]\n    -D --device   device to use (default /dev/spidev1.1)\n    -s --speed    max speed (Hz)\n    -d --delay    delay (usec)\n    -b --bpw      bits per word\n    -i --input    input data from a file (e.g. \"test.bin\")\n    -o --output   output data to a file (e.g. \"results.bin\")\n    -l --loop     loopback\n    -H --cpha     clock phase\n    -O --cpol     clock polarity\n    -L --lsb      least significant bit first\n    -C --cs-high  chip select active high\n    -3 --3wire    SI/SO signals shared\n    -v --verbose  Verbose (show tx buffer)\n    -p            Send data (e.g. \"1234\\xde\\xad\")\n    -N --no-cs    no chip select\n    -R --ready    slave pulls low to pause\n    -2 --dual     dual transfer\n    -4 --quad     quad transfer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fspidev-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frm-hull%2Fspidev-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fspidev-test/lists"}