Skip to content

Add support register-based SPI slave - #3040

Open
philrittenhouse wants to merge 1 commit into
stm32duino:mainfrom
philrittenhouse:main
Open

Add support register-based SPI slave#3040
philrittenhouse wants to merge 1 commit into
stm32duino:mainfrom
philrittenhouse:main

Conversation

@philrittenhouse

Copy link
Copy Markdown

By adding a method to the SPI library to read and write one byte at a time, the slave's code can implement a complete register-based SPI slave. The new method includes timeouts so that the slave does not get stuck in an infinite while loop if something goes wrong.

An additional reset() method can be used to reset the spi interface This allows the slave to recover if it falls behind or detects other errors that cause it to fall out sync with the master.

Example code showing a simple register-based slave is included in the SPI/examples/RegisterSlave folder along with a python script that runs on a RPi and acts as the master.

Resolves: #3039
See Also: #2050

Pull Request template

Summary

This PR fixes/implements the following bugs/features

  • Add support for register-based SPI slave
  • Add SPI slave example code

The current SPI slave support needs to expose additional functionality in order for the user code to implement a register-based SPI slave.

In a register-based SPI slave, the slave maintains a list of registers that the master can read or write. The registers can be read to return state (e.g. temperature or mode) or written to change state (e.g. set mode, control outputs).

By adding a method to read and write one byte at a time, the slave's code can implement a complete register-based SPI slave. The slave code works by waiting for an interrupt from the master on SS. It then read a byte containing the read/write bit and an address. It then either reads the data to be written to the given address, or returns the data read from the given address.

Using the spi_transfer() method doesn’t work for this use case because the slave does not know in advance if the master is starting a read or a write request and must determine that on the fly.

Validation

  • Ensure CI build is passed.
  • Demonstrate the code is solid. [e.g. Provide a sketch]

Code formatting

  • Ensure AStyle check is passed thanks CI

Closing issues

Fixes #3039
Closes: #3039

By adding a method to read and write one byte at a time, the slave's
code can implement a complete register-based SPI slave.
The new method includes timeouts so that the slave does not get stuck
in an infinite while loop if something goes wrong.

An additional reset() method can be used to reset the spi interface
This allows the slave to recover if it falls behind or detects other errors
that cause it to fall out sync with the master.

Example code showing a simple register-based slave is included in the
SPI/examples/RegisterSlave folder along with a python script that runs
on a RPi and acts as the master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add register-based SPI slave support with example code

1 participant