Embedded

Index - JaxCoder

PB0 Functions

FunctionDescription
GPIO InputRead a push button or switch
GPIO OutputControl an LED, relay, or buzzer
ADC InputRead analog signals from sensors (if enabled on this pin)
EXTIExternal interrupt input
Timer / Alternate FunctionPWM generation or timer input/output (depending on the timer mapping)

Common Uses

1. LED Control

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);   // LED ON
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // LED OFF

2. Push Button

if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0) == GPIO_PIN_SET)
{
    // Button is pressed
}

3. Analog Sensor

You can connect:

  • Potentiometer
  • LM35 Temperature Sensor
  • LDR
  • Soil Moisture Sensor (analog output)

to PB0 if it is configured as an ADC input.

4. PWM Output

PB0 can be configured as a timer output to:

  • Control LED brightness
  • Drive a servo motor
  • Control DC motor speed

Pin Type

PB0
│
├── GPIO
├── ADC
├── EXTI
└── Timer (Alternate Function)

In STM32CubeMX

Click PB0 and you can configure it as:

  • GPIO_Input
  • GPIO_Output
  • ADC
  • Timer/PWM (if supported)
  • Other alternate functions supported by the MCU

AGND Pin

AGND = Analog Ground

Purpose

AGND provides a clean, low-noise ground for analog circuits.

Devices connected to AGND

  • 🌡️ LM35 Temperature Sensor
  • 🌡️ TMP36
  • 💧 Soil Moisture Sensor (Analog Output)
  • 🔆 LDR (with voltage divider)
  • 🔘 Potentiometer
  • 🎤 Analog Microphone
  • 📈 Any sensor connected to an ADC pin

Example Circuit

      STM32

3.3V ──────────────┐
                   │
             Potentiometer
                   │
              PA0 (ADC)
                   │
AGND ──────────────┘

Here:

  • 3.3V supplies the sensor.
  • PA0 reads the analog voltage.
  • AGND is the reference ground.PB13 means:

    • P = Port
    • B = Port B
    • 13 = Pin number 13

    So PB13 = Port B, Pin 13.

    On the STM32C031C6, PB13 is a general-purpose I/O (GPIO) pin that can also support alternate functions depending on the microcontroller's pin mapping.

    PB13 Functions

    FunctionUse
    GPIO InputRead a button or switch
    GPIO OutputControl an LED, relay, or buzzer
    EXTIExternal interrupt
    Alternate FunctionTimer, SPI, or other peripheral (depending on the MCU configuration)

    Example 1: LED

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);   // LED ON
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); // LED OFF

    Example 2: Button

    if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13) == GPIO_PIN_SET)
    {
        // Button pressed
    }

    Typical Uses

    • ✅ LED control
    • ✅ Push button input
    • ✅ External interrupt (EXTI)
    • ✅ PWM output (if configured as a timer channel)
    • ✅ SPI signal (if mapped to SPI through an alternate function)

    GPIO vs Alternate Function

    PB13
    │
    ├── GPIO Output → LED
    ├── GPIO Input → Button
    ├── EXTI → Interrupt
    └── Alternate Function → SPI / Timer (if supported)

    PB14 Functions

    FunctionDescription
    GPIO InputRead a switch or sensor
    GPIO OutputControl an LED, relay, or buzzer
    EXTIExternal interrupt input
    TIM1_CH2NComplementary output of Timer 1 Channel 2 (used in advanced PWM and motor control)
    EVENTOUTEvent output signal for internal events

    Pin Diagram

    PB14
    │
    ├── GPIO Input
    ├── GPIO Output
    ├── EXTI
    ├── TIM1_CH2N (Alternate Function)
    └── EVENTOUT

    Practical Uses

    1. GPIO Output (LED)

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);   // LED ON
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); // LED OFF

    2. GPIO Input (Button)

    if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14) == GPIO_PIN_SET)
    {
        // Button pressed
    }

    3. TIM1_CH2N (Advanced PWM)

    TIM1_CH2N is the complementary output of Timer 1 Channel 2. It is mainly used in:

    • Three-phase BLDC motor control
    • Inverters
    • Power converters
    • H-bridge and half-bridge circuits

    The "N" stands for Negative (complementary) output. It produces a PWM signal that is complementary to the main timer output, with programmable dead time to prevent both transistors in a half-bridge from turning on at the same time. 

    Is PB14 an ADC pin?

    ❌ No. PB14 does not support ADC on the STM32C031C6. It is intended for GPIO and timer-related functions. 

    If you're studying the STM32 NUCLEO-C031C6 from scratch, I can also explain every pin (PA0–PA15, PB0–PB15, PC14, PC15, PF0–PF3) in the same detailed format.

    TIM1_CH2N (Advanced PWM) what is it use

    TIM1_CH2N is the complementary (inverted) output of Timer 1, Channel 2.

    • TIM1 = Advanced Timer 1
    • CH2 = Channel 2
    • N = Complementary (negative) output

    Unlike a normal PWM output, TIM1_CH2N generates a signal that is the opposite of the main PWM output (TIM1_CH2).

    Example

    If the main PWM signal (TIM1_CH2) is:

    TIM1_CH2   ────████────████────

    Then the complementary output (TIM1_CH2N) is:

    TIM1_CH2N  ████────████────████

    To protect power transistors, the timer can insert a small dead time between the two signals:

    TIM1_CH2   ────████────████────
                     ↑    ↑
                  Dead Time
    
    TIM1_CH2N  ████────████────████

    This ensures the two outputs are never ON at exactly the same time.

    Why is it used?

    It is mainly used to drive power electronics, where two switching devices must operate in a complementary manner.

    Applications

    • ⚙️ BLDC (Brushless DC) motor control
    • ⚙️ PMSM (Permanent Magnet Synchronous Motor) control
    • ⚡ DC-DC converters (Buck/Boost)
    • 🔋 Inverters (DC to AC)
    • 🔌 SMPS (Switched-Mode Power Supplies)
    • ⚡ H-Bridge and Half-Bridge motor drivers

    Example: Half-Bridge

          +12V
            |
          MOSFET (High Side)
            |
    --------+--------> Motor
            |
          MOSFET (Low Side)
            |
           GND
    • TIM1_CH2 controls the high-side MOSFET.
    • TIM1_CH2N controls the low-side MOSFET.

    The complementary outputs, together with dead time, prevent shoot-through—a condition where both MOSFETs conduct simultaneously and create a direct short from the supply to ground.

    Do beginners need it?

    Usually no.

    When starting STM32, you'll mainly use:

    • GPIO
    • UART
    • ADC
    • I²C
    • SPI
    • Standard PWM (for LEDs and servos)

    You'll encounter TIM1_CH2N when working on:

    • Motor control
    • Robotics
    • Industrial automation
    • Power electronics
    • Electric vehicle (EV) controllers

    So, TIM1_CH2N is a specialized PWM output designed for safely driving complementary switching devices in high-power electronic circuits.

    Functions of PB15

    FunctionDescription
    GPIO InputRead buttons, switches, or digital sensors
    GPIO OutputControl LEDs, relays, buzzers, etc.
    EXTI15External interrupt on pin 15
    TIM1_CH3NComplementary output of Timer 1 Channel 3 (Advanced PWM)
    EVENTOUTEvent output for internal MCU events

    PA8 Functions

    FunctionDescription
    GPIO InputRead buttons and digital sensors
    GPIO OutputControl LEDs, relays, buzzers
    EXTI8External interrupt
    TIM1_CH1Timer 1, Channel 1 PWM output
    MCO (Microcontroller Clock Output)Outputs the system clock or another internal clock to an external device
    EVENTOUTInternal event output

    1. GPIO Output

    Control an LED:

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);   // LED ON
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // LED OFF

    2. GPIO Input

    Read a push button:

    if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_8) == GPIO_PIN_SET)
    {
        // Button pressed
    }

    3. TIM1_CH1 (PWM)

    PA8 is the main PWM output of Timer 1 Channel 1.

    Typical applications:

    • LED brightness control
    • Servo motor control
    • DC motor speed control
    • PWM signal generation

    Example:

    PA8 (TIM1_CH1) ─── PWM ───► LED

    4. MCO (Microcontroller Clock Output)

    PA8 can output one of the MCU's internal clocks.

    Example uses:

    • Provide a clock to another microcontroller
    • Test the system clock with an oscilloscope
    • Synchronize external hardware

    5. EXTI8

    Configure PA8 as an external interrupt to respond immediately to:

    • Button presses
    • Motion sensors
    • Door sensors
    • Other digital events

    Is PA8 an ADC pin?

    ❌ No. PA8 does not support ADC on the STM32C031C6.


    Pin Summary

    PA8
    │
    ├── GPIO Input
    ├── GPIO Output
    ├── EXTI8
    ├── TIM1_CH1 (PWM)
    ├── MCO (Clock Output)
    └── EVENTOUT

    Comparison: PA8 vs PB13

    PA8PB13
    TIM1_CH1 (main PWM)TIM1_CH1N (complementary PWM)
    Drives the main outputDrives the complementary output
    Used for LEDs, servos, motorsUsed mainly in motor drives and power electronics

    So, PA8 (TIM1_CH1) and PB13 (TIM1_CH1N) are a pair:

    • PA8 outputs the main PWM signal.
    • PB13 outputs the complementary (inverted) PWM signal, often with programmable dead time for safe motor and power-switch control.
    pf3

    For the STM32C031C6PF3 means:

    • P = Port
    • F = Port F
    • 3 = Pin number 3

    Functions of PF3

    FunctionDescription
    GPIO InputRead a digital input
    GPIO OutputDrive an LED, relay, or buzzer
    NRST (Reset)Can be configured as the reset pin (depending on the option bytes)
    EXTI3External interrupt on pin 3
    EVENTOUTInternal event output

    1. GPIO Output

    Use PF3 to control an LED:

    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_3, GPIO_PIN_SET);   // LED ON
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_3, GPIO_PIN_RESET); // LED OFF

    2. GPIO Input

    Read a button:

    if(HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_3) == GPIO_PIN_SET)
    {
        // Button pressed
    }

    3. External Interrupt (EXTI3)

    PF3 can generate an interrupt when the input changes.

    Typical uses:

    • Push button
    • Motion sensor
    • Door sensor
    • Limit switch

    4. Reset Pin (NRST)

    On the STM32C031C6, PF3 shares functionality with the MCU reset pin. By default, it is used as NRST, allowing:

    • Resetting the microcontroller using the reset button.
    • Resetting the MCU with an external debugger (ST-LINK).

    On some STM32 devices, this pin can be reconfigured as a GPIO by changing the option bytes. If you do that, you lose the external reset function until it is restored.

    Pin Summary

    PF3
    │
    ├── GPIO Input
    ├── GPIO Output
    ├── EXTI3
    ├── NRST (Reset)
    └── EVENTOUT

Comments