dht11_stm32
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| dht11_stm32 [2024/07/29 15:41] – created oso | dht11_stm32 [2024/10/17 21:42] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 87: | Line 87: | ||
| Keep in mind that this approach assumes the CPU is running at exactly 72 MHz. If your MCU operates at a different frequency, you will need to adjust the inner loop count accordingly. | Keep in mind that this approach assumes the CPU is running at exactly 72 MHz. If your MCU operates at a different frequency, you will need to adjust the inner loop count accordingly. | ||
| + | |||
| + | |||
| + | ===== _delay_uSec ===== | ||
| + | |||
| + | |||
| + | Let's break down the `asm` line in the `_delay_uSec` function: | ||
| + | |||
| + | <code c> | ||
| + | __asm__ __volatile__(" | ||
| + | </ | ||
| + | |||
| + | Here's what each part means: | ||
| + | |||
| + | 1. **`__asm__`**: | ||
| + | |||
| + | 2. **`__volatile__`**: | ||
| + | |||
| + | 3. **`" | ||
| + | - **`nop`**: This is the "no operation" | ||
| + | - **`\n\t`**: These are escape sequences. `\n` is a newline character, and `\t` is a tab character. These are used for formatting the assembly code when it's outputted by the compiler. They help to make the generated assembly code more readable but don't affect the execution. | ||
| + | |||
| + | 4. **`:::" | ||
| + | - The first `:::` part separates the assembly instructions from the list of input, output, and clobbered registers. | ||
| + | - **`" | ||
| + | |||
| + | In summary, the line `__asm__ __volatile__(" | ||
| + | |||
| + | Here's the complete `_delay_uSec` function with this assembly code for context: | ||
| + | |||
| + | <code c> | ||
| + | void _delay_uSec(unsigned int i) { | ||
| + | for (; i > 0; i--) { // ' | ||
| + | for (int j = 0; j < 72; ++j) { // the 72 being the frequency in MHz the MCU is running | ||
| + | __asm__ __volatile__(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This function creates a delay by looping a number of times, with each loop containing 72 `nop` instructions to approximate a 1 microsecond delay, assuming the MCU is running at 72 MHz. | ||
dht11_stm32.1722267703.txt.gz · Last modified: 2024/10/17 21:42 (external edit)
