element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Raspberry pi as a SPI slave
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 657 subscribers
  • Views 3950 views
  • Users 0 members are here
  • slave
  • spi
  • raspberrypi
Related

Raspberry pi as a SPI slave

OriolPascual
OriolPascual over 1 year ago

Hi,

I need to configure a setup to have two SPI buses, with the Raspberry Pi acting as the slave in both cases. Despite searching extensively, I couldn't find any information on how to achieve this.

My conclusion is that the Raspberry Pi might not be designed for this specific use case, as it seems reluctant to operate as a slave device. However, I'm reaching out to see if anyone has managed to configure it in this way and if there are any resources or documentation available that could help me achieve this configuration.

Any guidance or insights would be greatly appreciated.

  • Sign in to reply
  • Cancel
  • dougw
    dougw over 1 year ago

    https://github.com/anetczuk/SpiSlave

    https://offis.github.io/raspi-directhw/group__spisl.html

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • 3tcubed
    3tcubed over 1 year ago

    I've used 2 ESP32-S3's as slave SPI devices (could have supported more), with the second core dedicated to comms with a master (Started with rPi4, moved to another ESP32-S3, may move the STM32 as I also need LoRa communications.  My findings were using any of these boards, I had to optomise the comms using the multi-core design to allow high speed communications on the SPi bus.  This did require locking to insure writes/memory updates were protected.  Initially my alternate comms was BT 5 (20-30 receptions/sec), but looking to longer distance and LoRa is next attempt.  I could not find any completed code, and had to "roll my own".  Getting the shared memory comms between cores was the real key to stability.  My SPI devices were parallel LCD displays, ideally I could have more than 2.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • BigG
    BigG over 1 year ago in reply to dougw

    Looks like these are the only options available, as in software driven spi slave mode.

    Looking at the Broadcom BCM2711 data sheet, it shows that only SPI master is the only hardware driver provided.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 1 year ago

    SPI slave is just an unusual interface configuration for such a system, so the options will have limitations (which you might or might not be able to live with), as you can see from the links Doug found for you. Just curious, what's the actual application?

    If you're looking for high-speed ways of interfacing, then there are interfaces like PCIe, or more longer-distant options like Ethernet or WiFi, very convenient since every Pi has a network interface of some sort.

    If you don't care for high throughout then there's UART. One SBC that could certainly do SPI slave (and do it with high performance) is BeagleBone Black with it's special hardware called PRU. But Pi doesn't have that.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • genebren
    genebren over 1 year ago

    If the Raspberry PI cannot easily be configured as a SPI slave module, you might be able to flip the scenario around and the Raspberry PIs repeatedly poll the master with a request for information, so that they can learn what the master wants and then do that.  I have had some success in this approach in the past (not related to the Raspberry Pi).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Dartmouth685
    Dartmouth685 over 1 year ago

    I believe the hardware supports SPI Slave, as the SPI Slave DMA DREQ is documented on the BCM2711 data sheet: https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf 
    The older BCM2835 goes into more details: https://datasheets.raspberrypi.com/bcm2835/bcm2835-peripherals.pdf

    I suggest trying the SPI slave registers on bare metal, with DMA. The closest starting point I'm aware of is the DMA driven SPIMaster in the Circle Bare Metal framework: https://github.com/rsta2/circle/blob/master/lib/spimasterdma.cpp  and to look at https://github.com/torvalds/linux/blob/23956900041d968f9ad0f30db6dede4daccd7aa9/drivers/spi/spi-bcm2835.c and finally https://github.com/hendric-git/bsc-slave

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 1 year ago in reply to Dartmouth685

    Interesting find. It's all quite ambiguous in the docs, the BCM2711 doesn't list it in the overview, but mentions some peripherals are missing from the list if they are controlled by the GPU.

    image

    Then in BCM2835, the list changes and specifically mentions SPI slave, but the reference to SPI master disappears off the list. (EDIT - I misread; it's there, on the next line, as SPI0-SPI2).

    image

    The result might be horribly device-specific and would need to be tested on different Pi versions I guess. 

    I'm now curious what the end application is, because if no-one's written a decent driver for Linux for SPI slave (apart from the workaround ones which have limitations) there could be other options which people have resorted to. Currently it's unknown though, just what throughput is required, and if regular polling as a master could be an option or not.

     OriolPascual care to shed some light on your actual use-case?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • OriolPascual
    OriolPascual over 1 year ago in reply to shabaz

    Sure.

    Firstly, a huge thanks to everyone for the incredible assistance provided on this forum.

    The application integrates edge computing with high-speed and high-precision ADC for industrial purposes. For the ADC component, we're considering the AD7768 paired with the CM4. This combination offers both computing power, digitalitzation capacity and the flexibility to utilize networking via Ethernet cable or Wi-Fi.

    Ideally, I would like to eliminate the necessity of a middleman serving as a data buffer, allowing both components to function as masters. However, if no other alternatives exist, I may have to resort to this approach.

    Regarding the communication protocol for the AD7768 (AD7768/AD7768-4 (Rev. C) (analog.com)).

    Dataready (DRDY) indicates a conversion is ready to be streamed, i plan to connect this to the CS, clock, and two data outputs, which will then be linked to the Master Output Slave Input (MOSI). While I acknowledge that this implementation may not be optimal, my intention is to avoid hardcoding the interface entirely.

    Said that, what is your opinion, and what would you di given the case?

    image

    Huge thanks to all of you for the help provided!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • michaelkellett
    michaelkellett over 1 year ago in reply to OriolPascual

    I've used the AD7768 and I very much doubt that you will ever get good performance with it directly connected to a micro. Few micros support SPI with multiple data lines and even those that do are aiming at memories rather than the AD7768's interface.

    The ADC requires a low jitter clock - usually at some frequency other than normal frequencies at which the micro operates. So you need to buffer the data and move it carefully between clock domains.

    High speed data transfer into a micro using SPI in slave mode requires the use of DMA and interrupts (or precision polling) and this will be very hard to achieve on a linux based OS.

    I would suggest that you use an FPGA between the processor and the ADC - this will allow you to operate the ADC. You don't need a monster FPGA, an Intel MAX10 or Efinix Trion (much cheaper) will do. A Lattice iCE40 part might do but may be too slow.

    image

    This picture shows the AD7768 and the Intel(Altera) Max10 FPGA ( and  a lot of analogue signal processing). If I did the design today I would use an Efinix FPGA (less than half the price in small numbers).

    MK

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to michaelkellett
    michaelkellett said:
    Few micros support SPI with multiple data lines and even those that do are aiming at memories rather than the AD7768's interface.

    one of the outliers: the TI Hercules family. Their SPIs support 4 data lines, and buffering, and DMA (and redundancy for your safety) . Not focusing on memory.

    I've used it to drive a colour LCD display.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube