... | ... | @@ -15,11 +15,12 @@ The SPI driver allow for sensors working with different bus configurations (baud |
|
|
|
|
|
Low level access to the SPI bus is implemented trough the SPI class, which provides access to all the peripheral functionalities and all the methods needed to perform operations on the bus, such as:
|
|
|
|
|
|
- `setClockDiver(ClockDivider divider)` configures the peripheral clock divider
|
|
|
- `setMode(Mode mode)` sets the clock polarity and phase
|
|
|
- `write(...)` writes bytes on the bus
|
|
|
- `read(...)` reads bytes from the bus
|
|
|
- `transfer(...)` performs a full duplex transaction, writing the provided bytes and returning the received bytes
|
|
|
- `SPI(SPI_TypeDef *spi)` The constructor automatically enables the clock for the specified SPI peripheral;
|
|
|
- `setClockDiver(ClockDivider divider)` configures the peripheral clock divider;
|
|
|
- `setMode(Mode mode)` sets the clock polarity and phase;
|
|
|
- `write(...)` writes bytes on the bus;
|
|
|
- `read(...)` reads bytes from the bus;
|
|
|
- `transfer(...)` performs a full duplex transaction, writing the provided bytes and returning the received bytes.
|
|
|
|
|
|
## SPIBus
|
|
|
|
... | ... | @@ -27,9 +28,9 @@ The lower level SPI driver is enhanced by the SPIBusInterface class. It is a vir |
|
|
|
|
|
### Interface implementations (SPIBus)
|
|
|
|
|
|
This interface is implemented primarly by the `SPIBus` class, which performs the _real_ operations on a SPI bus, using the SPI peripheral of the STM32F4 micro.\
|
|
|
This interface is implemented primarly by the `SPIBus` class, which performs, though the `SPI` class, operations on the bus using the peripheral of the STM32F4 micro.\
|
|
|
The interface may be implemented by other classes, for example `MockSpiBus`, that implements a "fake" SPI bus used for unit testing.\
|
|
|
The various **drivers must access the an SPI bus exclusively through the interface**. By doing this, the implementation of the driver is completely transparent to the use of a real SPI bus (`SPIBus`), a mock one (`MockSPIBus`) or other implementations: all can be used interchangeably without needing to change a single line of code in the driver.
|
|
|
The various **drivers must access the SPI bus exclusively through the interface**. By doing this, the implementation of the driver is completely transparent to the use of a real SPI bus (`SPIBus`), a mock one (`MockSPIBus`) or other implementations: all can be used interchangeably without needing to change a single line of code in the driver.
|
|
|
|
|
|
### SPITransaction
|
|
|
|
... | ... | @@ -95,10 +96,8 @@ int main() |
|
|
|
|
|
#### Notes
|
|
|
|
|
|
- The SPI peripheral and related GPIOs are not automatically configured by SPIDriver. They are usually configured in the `bsp.cpp` file for your board, in Miosix.\
|
|
|
- The related GPIOs are not automatically configured by SPIDriver. They are usually configured in the `bsp.cpp` file for your board, in Miosix.\
|
|
|
If not, you have to:
|
|
|
- Enable the SPI peripheral clock\
|
|
|
Example: `RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;`
|
|
|
- Set `MISO`, `MOSI`, `CLOCK` GPIOs to the correct alternate mode
|
|
|
- Set `CS` GPIO to output mode, and set its value to _high_.
|
|
|
- The `SPIBus` object is shared among all slaves on the same physical bus. It must thus be passed **by reference** to each slave.
|
... | ... | |