|
|
|
|
|
It's time to try out the SPI driver that we wrote in the previous tutorial.
|
|
It's time to try out the SPI driver that we wrote in the previous tutorial.
|
|
|
|
|
|
This example uses the [LIS3DSH](https://www.st.com/resource/en/datasheet/lis3dsh.pdf) accelerometer and temperature sensor that present on the STM32F407VG discovery board.
|
|
This example uses the _LIS3DSH_ accelerometer and temperature sensor that present on the STM32F407VG discovery board.
|
|
You can find an implementation for the accelerometer and the temperature sensor in `src/shared/sensors/LIS3DSH/LIS3DSH.h`.
|
|
You can find an implementation for the accelerometer and the temperature sensor in `src/shared/sensors/LIS3DSH/LIS3DSH.h`.
|
|
Here we will only consider reading the temperature data.
|
|
Here we will only consider reading the temperature data.
|
|
|
|
|
|
> :warning: **As a suggestion keep the sensor's datasheet with you while following the tutorial and try to find in it all the things that here are mentioned.**
|
|
> :information_source: **Suggestion: keep the sensor's datasheet with you while following the tutorial and try to find in it all the things that here are mentioned. This datasheet is pretty simple and it's useful to start dealing with this type of documents.**
|
|
|
|
|
|
## Header file
|
|
## Header file
|
|
We define the methods that we will be implemented in the `cpp` file:
|
|
We define the methods that we will be implemented in the `cpp` file:
|
... | @@ -44,22 +44,23 @@ private: |
... | @@ -44,22 +44,23 @@ private: |
|
const uint8_t TEMPERATURE_REF = 25;
|
|
const uint8_t TEMPERATURE_REF = 25;
|
|
};
|
|
};
|
|
```
|
|
```
|
|
In order to configure the _ODR_ and _BDU_ values we can define two `enum` that contain all the possible values for those two variables. All these values can be found in the sensor's datasheet.
|
|
In order to configure the _ODR_ and _BDU_ values we can define two `enum` that contain all the possible values for those two variables. All these values can be found in the sensor's datasheet.
|
|
Since the default value of _ODR_ is `ODR_POWER_DOWN` we have to set a different value in order for the sensor to work.
|
|
|
|
|
|
> :warning: **Since the default value of _ODR_ is `ODR_POWER_DOWN` (i.e. the sensor is turned off), we are obliged to configure the _ODR_ value in order for the sensor to work.**
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
enum OutputDataRate : uint8_t
|
|
enum OutputDataRate : uint8_t
|
|
{
|
|
{
|
|
ODRPOWER_DOWN = 0, // default value
|
|
ODR_POWER_DOWN = 0, // default value
|
|
ODR_3_125_HZ = 1,
|
|
ODR_3_125_HZ = 1,
|
|
ODR_6_25_HZ = 2,
|
|
ODR_6_25_HZ = 2,
|
|
ODR_12_5_HZ = 3,
|
|
ODR_12_5_HZ = 3,
|
|
ODR_25_HZ = 4,
|
|
ODR_25_HZ = 4,
|
|
ODR_50_HZ = 5,
|
|
ODR_50_HZ = 5,
|
|
ODR_100_HZ = 6,
|
|
ODR_100_HZ = 6,
|
|
ODR_400_HZ = 7,
|
|
ODR_400_HZ = 7,
|
|
ODR_800_HZ = 8,
|
|
ODR_800_HZ = 8,
|
|
ODR_1600_HZ = 9
|
|
ODR_1600_HZ = 9
|
|
};
|
|
};
|
|
|
|
|
|
enum BlockDataUpdate : uint8_t
|
|
enum BlockDataUpdate : uint8_t
|
... | @@ -182,7 +183,7 @@ int main() |
... | @@ -182,7 +183,7 @@ int main() |
|
```
|
|
```
|
|
|
|
|
|
## Compile with SBS
|
|
## Compile with SBS
|
|
Let's write our dependencies section. We need `Debug.cpp` (for the *TRACE()* function) and the source code of the SPI driver:
|
|
Let's write our dependencies section. We need `Debug.cpp` (for the _TRACE()_ function) and the source code of the SPI driver:
|
|
```sh
|
|
```sh
|
|
[spi_driver]
|
|
[spi_driver]
|
|
Type: srcfiles
|
|
Type: srcfiles
|
... | @@ -201,4 +202,10 @@ Main: test-tempsensor |
... | @@ -201,4 +202,10 @@ Main: test-tempsensor |
|
```
|
|
```
|
|
|
|
|
|
## Run it!
|
|
## Run it!
|
|
Same as before: build the entrypoint with `python sbs -b test-tempsensor` and [flash the binary on the board](Flashing-on-a-Target-Board). |
|
Same as before: build the entrypoint with `python sbs -b test-tempsensor` and [flash the binary on the board](Flashing-on-a-Target-Board).
|
|
\ No newline at end of file |
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
* [LIS3DSH datasheet](https://www.st.com/resource/en/datasheet/lis3dsh.pdf)
|
|
|
|
|
|
|
|
* [LIS3DSH Application Note](https://www.st.com/resource/en/application_note/dm00026768-lis3dsh-3axis-digital-output-accelerometer-stmicroelectronics.pdf) |
|
|
|
\ No newline at end of file |