diff options
| author | Milton Eduardo Sosa <31409391+snorkman88@users.noreply.github.com> | 2024-10-02 20:46:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-02 18:46:42 +0000 |
| commit | 87a8b7490866cda9e5c6819eeb357647bdb8d36e (patch) | |
| tree | 3b69862d31adfd0bc09d9098a9a998eaf4349295 /examples/stm32f411_encoder_polling/README.md | |
| parent | 805ea267a8515b7ee70125f444763f4aaa95c454 (diff) | |
Add example to poll encoder and display value on I2C display (#963)
Co-authored-by: Milton Eduardo Sosa <milton@Miltons-MacBook-Pro.local>
Diffstat (limited to 'examples/stm32f411_encoder_polling/README.md')
| -rw-r--r-- | examples/stm32f411_encoder_polling/README.md | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/stm32f411_encoder_polling/README.md b/examples/stm32f411_encoder_polling/README.md new file mode 100644 index 0000000..70fb1e8 --- /dev/null +++ b/examples/stm32f411_encoder_polling/README.md @@ -0,0 +1,64 @@ +# STM32F411CEU6 encoder polling and LCD display + +This example uses an STM32F411CEU6 microcontroller on the Blackpill board to interface with an I2C LCD display and a rotary encoder. + + +## Features + +- **Rotary Encoder Integration**: Reads input from a rotary encoder to adjust a value. +- **I2C LCD Display**: Displays the current encoder value on an I2C-connected HD44780 LCD. + + +## Working principle +The hardware task `tim2_timeout_interrupt_handler` polls the encoder state on each interrupt generated by TIM2, and updates the displayed value accordingly. + + +## Code Overview + +### Key Components + +- **Knob Struct**: Placeholder for the rotary encoder and its current value. +- **LCD I2C Communication**: Uses I2C protocol to communicate with the HD44780 LCD. +- **Timers**: Utilizes TIM1 for delays and TIM2 for polling the rotary encoder. + +### Important Constants + +- `LCD_I2C_ADDRESS`: The I2C address of the LCD display. + +### Initialization + +- **System Clock**: Configured to use an external 25 MHz clock. +- **GPIO Setup**: Configures GPIO pins for the LED, rotary encoder, and I2C communication. +- **I2C Initialization**: Sets up the I2C bus for LCD communication. +- **LCD Initialization**: Initializes the LCD and displays initial messages. +- **Timer Setup**: Configures TIM2 at 2 kHz and generate interrupts. + +### Tasks and Handlers + +- **idle**: Background task that runs when no other tasks are active. +- **tim2_timeout_interrupt_handler**: Handles interrupts generated by TIM2, updates the rotary encoder value, and displays the value on the LCD. + +### Utility Functions + +- `u8_to_str(n: u8) -> [u8; 3]`: Converts an 8-bit integer to a 3-character string representation. + + +## Dependencies + +- **hd44780-driver**: Driver for HD44780 LCD over I2C. +- **rotary_encoder_embedded**: Library for handling rotary encoders. +- **defmt**: Logging framework for embedded systems. + + +## How-to + +### Build +Run `cargo build --release` to compile the code. If you run it for the first time, it will take some time to download and compile dependencies. + +### Run +Install `probe-rs` and configure it using the [debugging extension for VScode](https://probe.rs/docs/tools/debugger/). +The output should look like this: + +[](https://www.youtube.com/watch?v=nn75gWDhHn0) + + |
