machine/attiny85: add USI-based SPI support #5181
Draft
+199
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implement SPI communication for ATtiny85 using the USI (Universal Serial Interface) hardware in three-wire mode. The ATtiny85 lacks dedicated SPI hardware but can emulate SPI using the USI module with software clock strobing.
Implementation
The implementation uses the USI control register (USICR) to toggle the clock pin, which triggers automatic bit shifting in hardware.
Frequency Configuration
The ATtiny85 USI lacks hardware prescalers, so frequency is controlled via software delay loops between clock toggles:
SPI Mode Configuration
All 4 SPI modes are supported:
Bit Order Configuration
Both MSB-first (default) and LSB-first bit orders are supported:
LSB-first is implemented via software bit reversal since the USI hardware only supports MSB-first.
References